php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #39251 variable variable class array property is read only
Submitted: 2006-10-25 00:34 UTC Modified: 2006-11-02 01:00 UTC
Votes:2
Avg. Score:4.5 ± 0.5
Reproduced:2 of 2 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (50.0%)
From: taskfreak at gmail dot com Assigned:
Status: No Feedback Package: Class/Object related
PHP Version: 5.1.6 OS: mac os
Private report: No CVE-ID: None
 [2006-10-25 00:34 UTC] 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
)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-10-25 07:08 UTC] derick@php.net
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
 [2006-11-02 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Oct 15 20:01:27 2024 UTC