<?//--这是我测试能否传递自身的地址。
class tree{
var $treearray;//--随便一个变量,
var $parent;
function tree($treearray,$parent=null) {
$this->treearray=$treearray;
if(is_null($parent))
$this->parent=&$this;//--为什么传递的是它的值,而不是引用?
else
$this->parent=&$parent;
}
}
$node=new tree("wo");
$node->parent->treearray="hoahao"; //注意这里
echo $node->parent->treearray;//--输出"wo",我想得到hoahao ,该如何改?
print_r($node);
?>
hoahaotree Object
(
[treearray] => wo
[parent] => tree Object
(
[treearray] => hoahao
[parent] => *RECURSION*
))
class tree{
var $treearray;//--随便一个变量,
var $parent;
function tree($treearray,$parent=null) {
$this->treearray=$treearray;
if(is_null($parent))
$this->parent=&$this;//--为什么传递的是它的值,而不是引用?
else
$this->parent=&$parent;
}
}
$node=new tree("wo");
$node->parent->treearray="hoahao"; //注意这里
echo $node->parent->treearray;//--输出"wo",我想得到hoahao ,该如何改?
print_r($node);
?>
hoahaotree Object
(
[treearray] => wo
[parent] => tree Object
(
[treearray] => hoahao
[parent] => *RECURSION*
))
我希望通过修改$node的值而达到修改$node->parent的值,不知道能不能办到,(php 4.33)
你可以构造一个方法来完成
$this->parent=&$this
为什么&$this不是对他本身的引用,加不加&效果是一样的.
谢谢了。