#36484 [Opn->Asn]: Overloading bug

From: Date: Wed, 22 Feb 2006 07:55:39 +0000
Subject: #36484 [Opn->Asn]: Overloading bug
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-93515@lists.php.net to get a copy of this message
ID: 36484 Updated by: tony2001@php.net Reported By: dave at dgx dot cz -Status: Open +Status: Assigned Bug Type: Class/Object related Operating System: Windows XP PHP Version: 5.1.2 -Assigned To: +Assigned To: dmitry Previous Comments: ------------------------------------------------------------------------ [2006-02-22 02:06:00] dave at dgx dot cz Description: ------------ Overloading results in unexpectable behaviour when using two arrays in overloaded object. Reproduce code: --------------- // basic overloading usage class Test { private $vars = array(), $vars2 = array(); function __get($name) { return $this->vars[$name]; } function __set($name, $value) { $this->vars[$name] = $value; } // initialize new variable function add($name, $value) { $this->vars[$name] = $value; // this second array is not used anymore - but it causes error $this->vars2[$name] = $value; } } $obj = new Test(); $obj->add('order', array(0, 1, 2)); // first test $obj->order[2] = $obj->order[1]; print_r($obj); // second test $obj->order[0] = 99; print_r($obj); Expected result: ---------------- // first test Test Object ( [vars:private] => Array ( [order] => Array ( [0] => 0 [1] => 1 [2] => 1 ) ) [vars2:private] => Array ( [order] => Array ( [0] => 0 [1] => 1 [2] => 2 ) ) // second test Test Object ( [vars:private] => Array ( [order] => Array ( [0] => 99 [1] => 1 [2] => 1 ) ) [vars2:private] => Array ( [order] => Array ( [0] => 0 [1] => 1 [2] => 2 ) ) Actual result: -------------- // first test Test Object ( [vars:private] => Array ( [order] => Array ( [0] => 0 [1] => 1 [2] => 2 ) ) [vars2:private] => Array ( [order] => Array ( [0] => 0 [1] => 1 [2] => 2 ) ) ) // second test Test Object ( [vars:private] => Array ( [order] => Array ( [0] => 99 [1] => 1 [2] => 2 ) ) [vars2:private] => Array ( [order] => Array ( [0] => 99 [1] => 1 [2] => 2 ) ) ) ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=36484&edit=1

« previous php.bugs (#93515) next »