ID:               33941
 Updated by:       [EMAIL PROTECTED]
 Reported By:      gordon at heydon dot com dot au
-Status:           Open
+Status:           Feedback
 Bug Type:         Class/Object related
 Operating System: linux / windows
 PHP Version:      5.0.4
 New Comment:

Please try using this CVS snapshot:

  http://snaps.php.net/php5-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5-win32-latest.zip




Previous Comments:
------------------------------------------------------------------------

[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

Reply via email to