#36484 [Asn]: Overloading bug

From: Date: Mon, 27 Feb 2006 23:51:07 +0000
Subject: #36484 [Asn]: Overloading bug
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-93739@lists.php.net to get a copy of this message
ID: 36484 User updated by: dave at dgx dot cz Reported By: dave at dgx dot cz Status: Assigned Bug Type: Class/Object related Operating System: Windows XP PHP Version: 5.1.2 Assigned To: dmitry New Comment: Sorry, my mistake. http://www.php.net/session says "The keys in the $_SESSION associative array are subject to the same limitations as regular variable names in PHP, i.e. they cannot start with a number..." 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 (#93739) next »