, $bar);
$bar = clone $foo;
$bar->member = "Something";
var_dump($foo, $bar);
?>
After hours of confusion and reading tons of posts I finally figured out that replacing PHP 4 style object creation, where new is assigned by reference:
$node_obj =& new someClass($somearg, $moreargs);
which in PHP 5.3.0 generates an E_STRICT message telling you that "Assigning the return value of new by reference is deprecated"
with the following, where & has been removed:
$node_obj = new someClass($somearg, $moreargs);
in some cases (at least in recursive loops while creating a tree of nodes containing child nodes) requires
unset($node_obj);
before the actual object assignment line to avoid all child nodes becoming identical.
Hope that delicate piece of information will save someone else a few hours.
In the following case you don't have to use = & operator when returning a reference:
<?php
class a {
public $a = 1;
}
class b {
static $var;
public static function & gvar($i) {
if(!(isset(b::$var[$i]))) {
b::$var[$i] = new a;
}
return b::$var[$i];
}
}
$b = new b;
$a = b
6/24 首页 上一页 4 5 6 7 8 9 下一页 尾页 |