| 
        php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
 PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits             
             [2006-08-01 22:57 UTC] tony2001@php.net
  | 
    |||||||||||||||||||||||||||||||||||||
            
                 
                Copyright © 2001-2025 The PHP GroupAll rights reserved.  | 
        Last updated: Tue Nov 04 15:00:01 2025 UTC | 
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 ) ) )