back on bug 42065 , strange behavior with ArrayObject

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi, at first, read that bug report : http://bugs.php.net/bug.php?id=42065

I would like to say that it doesn't seem to be fixed as it's said.
When I execute the bug 42065 test case, it still fails.

In reality, another code brought me to that bug, please consider this :

<?php
class a
{
    public $array = array('key'=>'2');

    public function getArray()
    {
        return $this->array;
    }

}
$a = new a;
$tab = $a->getArray();
$tab['key'] = 5;
print_r($a);
print_r($tab);

Outputs :
a Object
(
    [array] => Array
        (
            [key] => 2
        )

)
Array
(
    [key] => 5
)


No problem, that's expected.

Now consider that :

$a = new a;
$tab = new ArrayObject($a->getArray());
$tab['key'] = 5;
print_r($a);
print_r($tab);

Outputs :
a Object
(
    [array] => Array
        (
            [key] => 5
        )

)
ArrayObject Object
(
    [key] => 5
)


So, the original array, inside the 'a' object has been modified, but it
souldn't have.
This behavior is like the one described in bug 42065
Plateform : Windows
PHP : latest 5.2 snapshot - Apache SAPI.

If you really want the original array not to be modified, you should act
like this :
$tab = new ArrayObject((array)$a->getArray());

Strange isn't it ?

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux