#39251 [Opn->Fbk]: variable variable class array property is read only
| From: | derick@php.net | Date: | Wed, 25 Oct 2006 07:08:14 +0000 |
| Subject: | #39251 [Opn->Fbk]: variable variable class array property is read only | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-103954@lists.php.net to get a copy of this message | ||
ID: 39251
Updated by: derick@php.net
Reported By: taskfreak at gmail dot com
-Status: Open
+Status: Feedback
Bug Type: Class/Object related
Operating System: mac os
PHP Version: 5.1.6
New Comment:
Please try using this CVS snapshot:
http://snaps.php.net/php5.2-latest.tar.gz
For Windows:
http://snaps.php.net/win32/php5.2-win32-latest.zip
Previous Comments:
------------------------------------------------------------------------
[2006-10-25 00:34:02] taskfreak at gmail dot com
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 this bug report at http://bugs.php.net/?id=39251&edit=1