Professional Web Applications Themes

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

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: [url]http://www.entropy.ch/software/macosx/php/[/url] Reproduce code: --------------- class test { var $arrWhatever; function test() { $this->arrWhatever = array(); } ...

  1. #1

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

    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:
    [url]http://www.entropy.ch/software/macosx/php/[/url]


    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 [url]http://bugs.php.net/?id=39251&edit=1[/url]
    --
    Try a CVS snapshot (PHP 4.4): [url]http://bugs.php.net/fix.php?id=39251&r=trysnapshot44[/url]
    Try a CVS snapshot (PHP 5.2): [url]http://bugs.php.net/fix.php?id=39251&r=trysnapshot52[/url]
    Try a CVS snapshot (PHP 6.0): [url]http://bugs.php.net/fix.php?id=39251&r=trysnapshot60[/url]
    Fixed in CVS: [url]http://bugs.php.net/fix.php?id=39251&r=fixedcvs[/url]
    Fixed in release: [url]http://bugs.php.net/fix.php?id=39251&r=alreadyfixed[/url]
    Need backtrace: [url]http://bugs.php.net/fix.php?id=39251&r=needtrace[/url]
    Need Reproduce Script: [url]http://bugs.php.net/fix.php?id=39251&r=needscript[/url]
    Try newer version: [url]http://bugs.php.net/fix.php?id=39251&r=oldversion[/url]
    Not developer issue: [url]http://bugs.php.net/fix.php?id=39251&r=support[/url]
    Expected behavior: [url]http://bugs.php.net/fix.php?id=39251&r=notwrong[/url]
    Not enough info: [url]http://bugs.php.net/fix.php?id=39251&r=notenoughinfo[/url]
    Submitted twice: [url]http://bugs.php.net/fix.php?id=39251&r=submittedtwice[/url]
    register_globals: [url]http://bugs.php.net/fix.php?id=39251&r=globals[/url]
    PHP 3 support discontinued: [url]http://bugs.php.net/fix.php?id=39251&r=php3[/url]
    Daylight Savings: [url]http://bugs.php.net/fix.php?id=39251&r=dst[/url]
    IIS Stability: [url]http://bugs.php.net/fix.php?id=39251&r=isapi[/url]
    Install GNU Sed: [url]http://bugs.php.net/fix.php?id=39251&r=gnused[/url]
    Floating point limitations: [url]http://bugs.php.net/fix.php?id=39251&r=float[/url]
    No Zend Extensions: [url]http://bugs.php.net/fix.php?id=39251&r=nozend[/url]
    MySQL Configuration Error: [url]http://bugs.php.net/fix.php?id=39251&r=mysqlcfg[/url]
    taskfreak at gmail dot com Guest

  2. #2

    Default #39251 [Opn->Fbk]: variable variable class array property is read only

    ID: 39251
    Updated by: [email]derickphp.net[/email]
    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:

    [url]http://snaps.php.net/php5.2-latest.tar.gz[/url]

    For Windows:

    [url]http://snaps.php.net/win32/php5.2-win32-latest.zip[/url]


    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:
    [url]http://www.entropy.ch/software/macosx/php/[/url]


    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 [url]http://bugs.php.net/?id=39251&edit=1[/url]
    derick@php.net Guest

Similar Threads

  1. Read Dynamic Variable
    By Vayapues in forum Macromedia Flash Actionscript
    Replies: 1
    Last Post: March 1st, 08:41 PM
  2. Left side of assignment operator must be variable or property
    By anan in forum Macromedia Flash Actionscript
    Replies: 1
    Last Post: January 30th, 11:32 AM
  3. Read and insert to MySQL a URL-Variable
    By zack in forum PHP Development
    Replies: 1
    Last Post: October 15th, 08:25 AM
  4. #22237 [Com]: PHP crashes when class references property using variable variable
    By rep at devdomain dot com in forum PHP Development
    Replies: 0
    Last Post: September 29th, 11:34 AM
  5. Variable not read
    By Vishal Parkar in forum Microsoft SQL / MS SQL Server
    Replies: 0
    Last Post: July 10th, 11:14 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139