Bug #67899 [NEW]: __set() not firing when array is updated

From: Date: Sun, 24 Aug 2014 12:05:58 +0000
Subject: Bug #67899 [NEW]: __set() not firing when array is updated
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-187258@lists.php.net to get a copy of this message
From:             spikeon at gmail dot com
Operating system: Mac
PHP version:      5.5.16
Package:          Class/Object related
Bug Type:         Bug
Bug description:__set() not firing when array is updated

Description:
------------
__set() doesn't fire if the variable is an array and a new value is
pushed to that array

---
From manual page: http://www.php.net/language.oop5.magic
---


Test script:
---------------
class Foo(){
    private $info = [];
    function __set($k, $v){
        $this->info[$k] = $v;
    }
    function __get($k){
        return $this->info[$k] ?: null;
    }
}

$bar = new Foo();
$bar->foo = [];
$bar->foo[] = "foo1";
var_dump($bar->foo); // returns Array()

Expected result:
----------------
Upon update of the array, the array should be re-submitted to the
__set() method.  If this would cause issues, perhaps a new magic method
could be created to handle changes of this nature, eg: __update() or
__change().


-- 
Edit bug report at https://bugs.php.net/bug.php?id=67899&edit=1
-- 



Thread (3 messages)

« previous php.bugs (#187258) next »