References

From: Date: Sat, 30 Aug 2003 14:13:37 +0000
Subject: References
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-4260@lists.php.net to get a copy of this message
The current support for references is mediocre at best. For instance: 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, LingWitt@insightbb.com

« previous php.internals (#4260) next »