PHP 4.0 Bug #10088: Object linking

From: Date: Sat, 31 Mar 2001 09:58:18 +0000
Subject: PHP 4.0 Bug #10088: Object linking
Groups: php.dev 
Request: Send a blank email to php-dev+get-50405@lists.php.net to get a copy of this message
From: admin@room41.net Operating system: W2K PHP version: 4.0.4pl1 PHP Bug Type: Class/Object related Bug description: Object linking The script shown attempts to implement a linked list, but the problem is more general and occurs in many similar situations. <? $d1 = @new obj("one"); // Suppress the warning over the missing argument $d2 = new obj("two", $d1); $d3 = new obj("three", $d2); $d4 = new obj("four", $d3); $d5 = new obj("five", $d4); // Dump what should be the entire linked list $d1->dump(); print("<p>"); // Now to demonstrate the problem: // No matter where you begin the dump() from, only the // $this node and its immediate successor are printed. $d2->dump(); print("<p>"); $d3->dump(); print("<p>"); class obj { var $next; var $name; function &obj($name,&$prev) { // Add each new object as the "next" pointer of the preceeding one this->name = $name; if ($prev) $prev->next = $this; } function dump() { for ( $ptr = $this; $ptr; $ptr = $ptr->next) print($ptr->name . "<br>"); } } ?> It seems that when an object's data is manipulated by a different object - even as here, of the same class - the changes made to the object are lost when its context expires. Configuration: Absolutely standard Webserver: Apache and IIS ... same problem in both, and under cgi and as a module Aggravation factor: Immense Cheer chaps for an otherwise excellent language! -- Edit Bug report at: http://bugs.php.net/?id=10088&edit=1

« previous php.dev (#50405) next »