ID:               33941
 Comment by:       fanfatal at fanfatal dot pl
 Reported By:      gordon at heydon dot com dot au
 Status:           Assigned
 Bug Type:         Class/Object related
 Operating System: *
 PHP Version:      5CVS-2005-08-02
 Assigned To:      dmitry
 New Comment:

In PHP 5.0.4 this bug has been corrected

Greatings ;-)
...


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

[2005-08-18 09:27:48] [EMAIL PROTECTED]

Can we atleast make sure it gives a nice big warning on this? Now it
merely produces some leaks:
<?php

        class Foo {
                function __set($name, $value)
                {
                        var_dump($name, $value);
                }
        }


        $f = new Foo();

        $f->bar[1] = 42;

produces:
[EMAIL PROTECTED]:~$ php-6.0dev /tmp/foooo.php
/dat/dev/php/php-6.0dev/Zend/zend_execute.c(827) :  Freeing 0x08796494
(16 bytes), script=/tmp/foooo.php
/dat/dev/php/php-6.0dev/Zend/zend_execute.c(1005) :  Freeing 0x0879643C
(35 bytes), script=/tmp/foooo.php
/dat/dev/php/php-6.0dev/Zend/zend_hash.c(383) : Actual location
(location was relayed)
/dat/dev/php/php-6.0dev/Zend/zend_execute.c(1060) :  Freeing 0x087963DC
(44 bytes), script=/tmp/foooo.php
/dat/dev/php/php-6.0dev/Zend/zend_API.c(712) : Actual location
(location was relayed)
Last leak repeated 1 time
/dat/dev/php/php-6.0dev/Zend/zend_execute.c(1057) :  Freeing 0x087842CC
(16 bytes), script=/tmp/foooo.php
=== Total 5 memory leaks detected ===


------------------------------------------------------------------------

[2005-08-05 12:06:17] [EMAIL PROTECTED]

This is not fixable :(

------------------------------------------------------------------------

[2005-08-05 11:44:23] [EMAIL PROTECTED]

Dmitry "The Fixer", please check this out.


------------------------------------------------------------------------

[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

Reply via email to