From: [EMAIL PROTECTED] Operating system: Windows 2000 PHP version: 4.2.3 PHP Bug Type: Variables related Bug description: variable references not working correctly
The variable reference is not working as I would understand it should. The example that follows is long, but just cut and paste then read the output. Years of "C" programming says this should work. Try example first then, look for the following lines in the code: //*****NOTE****JUST DELETE THE & symbol TO MAKE WORK and remove the & symbol to see the correct output. CODE STARTS HERE ********************************************************** <?php class A { var $name; var $order; } class B { var $name; var $list_array; } class C_LIST { var $c_list; function print_test($call,$cname) { // call: the variable you want to print_r // cname: the label for your debugging output echo $cname . ":<pre>"; print_r($call); if ( is_array($call)) { reset($call); } echo "</pre><hr>"; } function test() { //new instantiated array in memory $local_c_list = array(); //array indicies for $i = 0; $j = 0; //array indicies for $x (see below) $k = 0; $x = array(0 => array(0 => "A_First", 1 => "B_First", 2 => 1), 1 => array(0 => "A_First", 1 => "B_Second", 2 => 2), 2 => array(0 => "A_First", 1 => "B_Third",2 => 3), 3 => array(0 => "A_Second",1 => "B_First",2 => 1), 4 => array(0 => "A_Second",1 => "B_Second",2 => 2), 5 => array(0 => "A_Second",1 => "B_Third",2 => 3) ); //loop through in array of x, e.g. x[0][$l] for ($k = 0; $k < 6; $k = $k + 1) { $b_name = $x[$k][0]; $a_name = $x[$k][1]; $a_order = $x[$k][2]; if ((!isset($b)) || (!isset($b->name)) || ($b_name != $b->name)) { //attach the A record to the main list // starting on the second A record found if (isset($b->name)) { //set the local_list to the reference of b //this avoids memory copies //*****NOTE****JUST DELETE THE & symbol TO MAKE WORK $local_c_list[$i] = &$b; $i = $i + 1; $j = 0; } $b = new B(); $b->name = $b_name; $b->list_array = array(); $this->print_test($b,"An element"); } //end if no B exists or we are beginning another B name //Create new A record $a = new A(); $a->name = $a_name; $a->order = $a_order; $this->print_test($a,"An item"); //Set $b->list_array[$a->order] = &$a -- the reference of $a //*****NOTE****JUST DELETE THE & symbol TO MAKE WORK $b->list_array[$j] = &$a; $j = $j + 1; $this->print_test($b,"A list"); } //end for k loops $this->c_list = $local_c_list; return; } //end test } //end class $the_list = new C_LIST(); $the_list->test(); $the_list->print_test($the_list,"Test"); ?> -- Edit bug report at http://bugs.php.net/?id=20525&edit=1 -- Try a CVS snapshot: http://bugs.php.net/fix.php?id=20525&r=trysnapshot Fixed in CVS: http://bugs.php.net/fix.php?id=20525&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=20525&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=20525&r=needtrace Try newer version: http://bugs.php.net/fix.php?id=20525&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=20525&r=support Expected behavior: http://bugs.php.net/fix.php?id=20525&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=20525&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=20525&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=20525&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=20525&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=20525&r=dst IIS Stability: http://bugs.php.net/fix.php?id=20525&r=isapi