Passing Object Refs throught Arrays
| From: | James | Date: | Thu, 30 Jan 2003 12:36:20 +0000 |
| Subject: | Passing Object Refs throught Arrays | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-133635@lists.php.net to get a copy of this message | ||
I'm having a problem, and I wrote this sample code to illistrate it.
In this code, I'm trying to create a object, put it throught a que. I
then want something to happen to this object, and this change to be
reflected in the original object. I am aware that PHP uses copy
symantecs not refrence ones, so I have used "&" at all the places I can
see to use them. However it doesnt work: the output from this is still
0 not 100 as it should be.
Does anyone have any suggestions, or URL's to really good guides on
reference passing?
Thanks in Advance,
James.
---------------------
class test {
var $flag = 0;
}
// Make Object
$root = new test();
// Make Que
$que = array();
// Stick object on que
array_push($que, &$root);
// Take object from Que
$consider =& array_shift($que);
// Change something on the object we pulled from the que
$consider->flag = 100;
// Test and see if it changed on the original object
echo($root->flag);