ID: 33941
Updated by: [EMAIL PROTECTED]
Reported By: gordon at heydon dot com dot au
-Status: Open
+Status: Assigned
Bug Type: Class/Object related
Operating System: *
PHP Version: 5CVS-2005-08-02
-Assigned To:
+Assigned To: dmitry
New Comment:
Dmitry "The Fixer", please check this out.
Previous Comments:
------------------------------------------------------------------------
[2005-08-01 12:42:33] stochnagara at hotmail dot com
I've tested this with the lastest win32 binary package. The bug is
still present.
When __get prototype is changed to function & __get everything works
fine.
------------------------------------------------------------------------
[2005-08-01 05:48:59] gordon at heydon dot com dot au
Description:
------------
If using the __set() and __get() to store and manipulate arrays within
a property, if the array is not being stored as an array then the array
assignment will not work.
If in the example the property just has the value from the assignment
stored without the serialization, so storing the array within the array
this works.
Also the funny thing is that if you put echos within the __set() and
__get the $obj->prop[5] = 'apple' does not output anything at all. It
is like PHP is trying to guess what the __set() is doing and then doing
that,
Reproduce code:
---------------
<?php
class ex {
public function __get($prop) {
return unserialize($this->fields[$prop]);
}
public function __set($prop, $value) {
$this->fields[$prop] = serialize($value);
}
private $fields;
}
$obj = new ex;
$obj->prop = array(4 => 'pear');
$obj->prop[5] = 'apple';
var_dump($obj->prop);
?>
Expected result:
----------------
array(1) {
[4]=>
string(4) "pear"
[5]=>
string(5) "apple"
}
Actual result:
--------------
array(1) {
[4]=>
string(4) "pear"
}
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=33941&edit=1