php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #36484 Overloading bug
Submitted: 2006-02-22 02:06 UTC Modified: 2006-08-01 22:57 UTC
Votes:15
Avg. Score:4.5 ± 0.7
Reproduced:8 of 9 (88.9%)
Same Version:7 (87.5%)
Same OS:3 (37.5%)
From: dave at dgx dot cz Assigned: dmitry (profile)
Status: Closed Package: Class/Object related
PHP Version: 5.1.2 OS: Windows XP
Private report: No CVE-ID: None
 [2006-02-22 02:06 UTC] 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
                )

        )

)



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-08-01 22:57 UTC] tony2001@php.net
Not reproducible with 5.2-CVS.
 
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Sun Sep 25 17:05:53 2022 UTC