Hi, Thursday, January 30, 2003, 10:36:20 PM, you wrote:
J> I'm having a problem, and I wrote this sample code to illistrate it. J> In this code, I'm trying to create a object, put it throught a que. I J> then want something to happen to this object, and this change to be J> reflected in the original object. I am aware that PHP uses copy J> symantecs not refrence ones, so I have used "&" at all the places I can J> see to use them. However it doesnt work: the output from this is still J> 0 not 100 as it should be. J> Does anyone have any suggestions, or URL's to really good guides on J> reference passing? J> Thanks in Advance, J> James. J> --------------------- J> class test { J> var $flag = 0; J> } J> // Make Object J> $root = new test(); J> // Make Que J> $que = array(); J> // Stick object on que J> array_push($que, &$root); J> // Take object from Que J> $consider =& array_shift($que); J> // Change something on the object we pulled from the que $consider->>flag = 100; J> // Test and see if it changed on the original object echo($root->>flag); Here are some replacements that I use for handling references as the normal pop and push wont work: function array_ref_push(&$array,&$ref){ $array[] =& $ref; } function &array_ref_pop(&$array){ $r =& $array[count($array)-1]; array_pop($array); return $r; } function array_ref_unshift(&$array,&$ref){ array_unshift($array,''); $array[0] =& $ref; } function &array_ref_shift(&$array){ $r =& $array[0]; array_shift($array); return $r; } -- regards, Tom -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php