PHP易错面试题

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<?phpclass SomeClass{
    private $properties = [];
    public function __set($name, $value)
    {
       $this->properties[$name] = $value;
    }
    public function __get($name)
    {
        return $this->properties[$name];
    }}
$obj = new SomeClass();
$obj->name = 'phpgod';
$obj->age = 2;
$obj->gender = 'male';
var_dump($obj->name);
//output:string(6) "phpgod"
var_dump(isset($obj->name));
//output:bool(false),你的答案对了吗?为什么
<?php
   //第2题:
    $arr = [1,2,3];
    foreach($arr as &$v) {
        //nothing todo.
    }
    foreach($arr as &$v) {
        //nothing todo.
    }
    var_export($arr);
    //output:array(0=>1,1=>2,2=>2),你的答案对了吗?为什么?>
Posted in: PHP
ˆ Back To Top