class foobar { var $variable; function foobar() { $variable = "foobar"; } }
//This form of new assignment should be the default $a = & new foobar(); $b = & new foobar(); $b->variable = "Hello";
$array = array(&$a, &$b);
//The foreach construct uses copies instead of references. foreach ($array as $element) $element->variable = "Hi";
echo $a->variable; //echoes "foobar" echo $b->variable; //echoes "Hello";
//In order for the above to work, a loop is required. for ($i = 0, $count = count($array); $i < $count; $i++) { $element = &$array[$i]; //shown explicitly. $element->variable = "Hi"; }
echo $a->variable; //echoes "Hi" echo $b->variable; //echoes "Hi";
//Variable args are always copies, Function foo() { $args = func_get_args() //even loop doesn't work: for ($i = 0, $count = count($args); $i < $count; $i++) { $element = &$args[$i]; $element->variable = "Hello"; } }
foo(&$a, &$b); echo $a->variable; //echoes "Hi" echo $b->variable; //echoes "Hi";
Thanks for your time, [EMAIL PROTECTED]
-- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php