From:             dave at dgx dot cz
Operating system: Windows XP
PHP version:      5.1.2
PHP Bug Type:     Class/Object related
Bug description:  Overloading bug

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 bug report at http://bugs.php.net/?id=36484&edit=1
-- 
Try a CVS snapshot (PHP 4.4): 
http://bugs.php.net/fix.php?id=36484&r=trysnapshot44
Try a CVS snapshot (PHP 5.1): 
http://bugs.php.net/fix.php?id=36484&r=trysnapshot51
Try a CVS snapshot (PHP 6.0): 
http://bugs.php.net/fix.php?id=36484&r=trysnapshot60
Fixed in CVS:                 http://bugs.php.net/fix.php?id=36484&r=fixedcvs
Fixed in release:             
http://bugs.php.net/fix.php?id=36484&r=alreadyfixed
Need backtrace:               http://bugs.php.net/fix.php?id=36484&r=needtrace
Need Reproduce Script:        http://bugs.php.net/fix.php?id=36484&r=needscript
Try newer version:            http://bugs.php.net/fix.php?id=36484&r=oldversion
Not developer issue:          http://bugs.php.net/fix.php?id=36484&r=support
Expected behavior:            http://bugs.php.net/fix.php?id=36484&r=notwrong
Not enough info:              
http://bugs.php.net/fix.php?id=36484&r=notenoughinfo
Submitted twice:              
http://bugs.php.net/fix.php?id=36484&r=submittedtwice
register_globals:             http://bugs.php.net/fix.php?id=36484&r=globals
PHP 3 support discontinued:   http://bugs.php.net/fix.php?id=36484&r=php3
Daylight Savings:             http://bugs.php.net/fix.php?id=36484&r=dst
IIS Stability:                http://bugs.php.net/fix.php?id=36484&r=isapi
Install GNU Sed:              http://bugs.php.net/fix.php?id=36484&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=36484&r=float
No Zend Extensions:           http://bugs.php.net/fix.php?id=36484&r=nozend
MySQL Configuration Error:    http://bugs.php.net/fix.php?id=36484&r=mysqlcfg

Reply via email to