Bug #52540 [Opn->Bgs]: Error on update array's field through __set magic method
| From: | johannes@php.net | Date: | Thu, 05 Aug 2010 09:02:30 +0000 |
| Subject: | Bug #52540 [Opn->Bgs]: Error on update array's field through __set magic method | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-153112@lists.php.net to get a copy of this message | ||
Edit report at http://bugs.php.net/bug.php?id=52540&edit=1
ID: 52540
Updated by: johannes@php.net
Reported by: trong at ngs dot ru
Summary: Error on update array's field through __set magic
method
-Status: Open
+Status: Bogus
Type: Bug
Package: Class/Object related
Operating System: Windows XP
PHP Version: 5.3.3
Block user comment: N
New Comment:
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
When using the array as storage the __get() method will return a copy of
the array. When using ArrayObject it will return a handle to the object.
So with an array you're working on a copy, with objects on the same
object.
For objet handles check
http://www.php.net/manual/en/language.oop5.references.php
Previous Comments:
------------------------------------------------------------------------
[2010-08-05 09:43:33] trong at ngs dot ru
Description:
------------
If I use __set magic method for arrays and try to update some field of
array I see
the old value. But, if I use the same scheme for ArrayObject I'll get
the right
result.
Test script:
---------------
<?
class t
{
private $data = array();
public function __get($name) {
return $this->data[$name];
}
public function __set($name, $value) {
$this->data[$name] = $value;
}
}
// define test array
$array = array( 'view' => array('x' => 1, 'y' => 1) );
$t = new t();
$t->mas = $array;
// update field of array
$t->mas['view']['x'] = 1111;
echo $t->mas['view']['x'];
echo '<br>';
$t->mas2 = new ArrayObject($array);
$t->mas2['view']['x'] = 1111;
echo $t->mas2['view']['x'];
?>
Expected result:
----------------
1111
<br>
1111
Actual result:
--------------
1
<br>
1111
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/bug.php?id=52540&edit=1