|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2007-05-14 08:27 UTC] judas dot iscariote at gmail dot com
[2007-05-14 08:43 UTC] peter at ibuildings dot nl
[2007-05-14 19:10 UTC] derick@php.net
[2007-05-14 20:29 UTC] peter at ibuildings dot nl
[2007-08-17 08:31 UTC] vrana@php.net
[2007-08-17 09:58 UTC] peter at ibuildings dot nl
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Nov 06 19:00:01 2025 UTC |
Description: ------------ I've created a small class that implements the magic __set, __get and __isset methods. Using PHP 5.1.6 I can assign an array to a "fake" instance variable and then add elements to it. Doing the same using PHP 5.2.1 or 5.2.2 doesn't change the contents of the array. I've tried returning a reference from the __get method (e.g. changes the function definition to "function &__get($key, $value) ...", but this doesn't work either (although PHP doesn't complain about it). If this wasn't supposed to work with PHP 5.1.6 how should I then implement this to get the desired behaviour? If this isn't possible at all then that means __set/__get are far less usable then before. Reproduce code: --------------- class Data { private $m_data = array(); function __set($key, $value) { $this->m_data[$key] = $value; } function __get($key) { return $this->m_data[$key]; } function __isset($key) { return isset($this->m_data[$key]); } function dump() { var_dump($this->m_data); } } $obj = new Data(); $obj->a = "a"; $obj->b = array(); $obj->b[] = '1'; $obj->b[] = '2'; $obj->b[] = '3'; $obj->dump(); Expected result: ---------------- array(2) { ["a"]=> string(1) "a" ["b"]=> array(3) { [0]=> string(1) "1" [1]=> string(1) "2" [2]=> string(1) "3" } } Actual result: -------------- array(2) { ["a"]=> string(1) "a" ["b"]=> array(0) { } }