#39251 [NEW]: variable variable class array property is read only

From: Date: Wed, 25 Oct 2006 00:34:03 +0000
Subject: #39251 [NEW]: variable variable class array property is read only
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-103951@lists.php.net to get a copy of this message
From: taskfreak at gmail dot com Operating system: mac os PHP version: 5.1.6 PHP Bug Type: Class/Object related Bug description: variable variable class array property is read only Description: ------------ Acessing class property (which is an array) using a variable makes it read only (can not add a new element) See code if you don't understand what I mean. $this->$nameOfArray[$key] = $value; Using PHP4 style, haven't tried it in PHP5 class coding style. I'm under mac os, using php 5.1.6, installed by following this: http://www.entropy.ch/software/macosx/php/ Reproduce code: --------------- class test { var $arrWhatever; function test() { $this->arrWhatever = array(); } function set($where,$who, $what) { $this->$where[$who] = $what; } function set2($where,$who,$what) { $arrTmp =& $this->$where; $arrTmp[$who] = $what; } } $obj = new test(); $obj->set('arrWhatever','key','value'); print_r($obj->arrWhatever); $obj->set2('arrWhatever','key','value'); print_r($obj->arrWhatever); Expected result: ---------------- Array ( [key] => value ) Array ( [key] => value ) Actual result: -------------- Array ( ) Array ( [key] => value ) -- Edit bug report at http://bugs.php.net/?id=39251&edit=1 -- Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=39251&r=trysnapshot44 Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=39251&r=trysnapshot52 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=39251&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=39251&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=39251&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=39251&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=39251&r=needscript Try newer version: http://bugs.php.net/fix.php?id=39251&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=39251&r=support Expected behavior: http://bugs.php.net/fix.php?id=39251&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=39251&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=39251&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=39251&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=39251&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=39251&r=dst IIS Stability: http://bugs.php.net/fix.php?id=39251&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=39251&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=39251&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=39251&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=39251&r=mysqlcfg

« previous php.bugs (#103951) next »