<?php
class A{
public $data;
public $obj;
function __construct()
{
$this->data = array();
$this->obj = new stdClass();
}
function __set($name, $value)
{
$this->data[$name] = $value;
if (is_object($this->obj)) {
$this->obj->$name = $value;
}
}
function __get($name)
{
if (is_object($this->obj)) {
return $this->obj->$name;
}
}
}
$a = new A();
$a->a = '123';
var_dump($a->a); //123
echo "<br>";
var_dump(empty($a->a)); //true,为什么这里会是true?百思不得其解,bug?
echo "<br>";
$b = $a->a;
var_dump(empty($b)); //false
?>