From: gordon at heydon dot com dot au
Operating system: linux / windows
PHP version: 5.0.4
PHP Bug Type: Class/Object related
Bug description: overloading not working with arrays not stored as arrays
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 bug report at http://bugs.php.net/?id=33941&edit=1
--
Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=33941&r=trysnapshot4
Try a CVS snapshot (php5.0):
http://bugs.php.net/fix.php?id=33941&r=trysnapshot50
Try a CVS snapshot (php5.1):
http://bugs.php.net/fix.php?id=33941&r=trysnapshot51
Fixed in CVS: http://bugs.php.net/fix.php?id=33941&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=33941&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=33941&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=33941&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=33941&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=33941&r=support
Expected behavior: http://bugs.php.net/fix.php?id=33941&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=33941&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=33941&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=33941&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=33941&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=33941&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=33941&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=33941&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=33941&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=33941&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=33941&r=mysqlcfg