如果在PHP5中通过引用传递对象,为什么以下内容始终显示123
然后xyz
,而不是abc
然后xyz
这是我期望的?
<?php
class CustomDOMElement extends DOMElement
{
public $custom_property = '123';
public function echoCustomProperty()
{
var_dump($this->custom_property);
}
}
$document = new DOMDocument();
$document->registerNodeClass('DOMElement', 'CustomDOMElement');
$document->loadHTML('<div>Hi, this is a test</div>');
$document->documentElement->custom_property = 'abc';
$document->documentElement->echoCustomProperty();
$elem = &$document->documentElement;
$elem->custom_property = 'xyz';
$elem->echoCustomProperty();
?>
我是否总是必须像$elem
那样明确地存储引用,以便在元素上设置属性?