Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/269.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/facebook/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP DOM、类属性和通过引用传递对象_Php_Oop_Pass By Reference - Fatal编程技术网

PHP DOM、类属性和通过引用传递对象

PHP DOM、类属性和通过引用传递对象,php,oop,pass-by-reference,Php,Oop,Pass By Reference,如果对象在PHP5中是通过引用传递的,为什么下面的内容总是显示123然后xyz,而不是我所期望的abc然后xyz <?php class CustomDOMElement extends DOMElement { public $custom_property = '123'; public function echoCustomProperty() { var_dump($this->custom_property); } }

如果对象在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
那样显式存储引用