copy of object is not copy PHP4.0.4 serious BUG

From: Date: Tue, 06 Mar 2001 18:20:51 +0000
Subject: copy of object is not copy PHP4.0.4 serious BUG
Groups: php.dev 
Request: Send a blank email to php-dev+get-48080@lists.php.net to get a copy of this message
Hello, consider following two classes: class TDynVars { var $vars; function set ($key, $val) { $this->vars[$key] = $val; } } class TRequest { var $eventData; function TRequest () { $this->eventData = new TDynVars; } } and two programs, A and B. program A: $r1 = new TRequest; $r1->eventData->vars[0]=1; $r2 = $r1; $r2->eventData->vars[0]=2; print($r1->eventData->vars[0]); output of program A should be "1" and is "1", it is OK. program B: $r1 = new TRequest; $r1->eventData->set(0,1); $r2 = $r1; $r2->eventData->vars[0]=2; print($r1->eventData->vars[0]); output of program B should be obviously "1" and is "2", it is NOT OK. Why $r2 changes data of $r1 if $r2 is $r1's copy by value not reference? Why this faulty behaviour is dependent on indirect access using member function use instead of direct acces? Note: The program B on PHP3.0.8 runs correctly, but not on PHP4.0.4. Thank you for solving this fundamental problem. Roland Divin

« previous php.dev (#48080) next »