php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #28237 Can't access built in array whose name is stored in an object attribute
Submitted: 2004-04-30 18:57 UTC Modified: 2004-04-30 19:58 UTC
From: marcel at vernix dot org Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 4.3.4 OS: Debian GNU/Linux 2.4.20
Private report: No CVE-ID: None
 [2004-04-30 18:57 UTC] marcel at vernix dot org
Description:
------------
When the name of a built in array is stored inside of an object attribute, its contents can't be access from the 'variable variable' without the use of eval.

So, print_r(${$this->array}) and print_r($$this->array) don't work, but eval("print_r(\${$this->array});") does.

When trying the same thing on a "regular" variable variable, it works as expected.

Reproduce code:
---------------
<?php
$built_in_array = '_SERVER';

class klass {

    function klass($array = '_SERVER') {
        $this->array = $array;
    }

    function printit() {
        print_r(${$this->array});
        #eval ("print_r(\${$this->array});");
    }
}   

print_r(${$built_in_array});

$k = new klass();
$k->printit();
?>

Expected result:
----------------
Array
(
    [HZ] => 100
    [TERM] => rxvt
    [SHELL] => /bin/bash
    [WINDOWID] => 31457282
...etc...

Array
(
    [HZ] => 100
    [TERM] => rxvt
    [SHELL] => /bin/bash
    [WINDOWID] => 31457282
...etc...

Actual result:
--------------
Array
(
    [HZ] => 100
    [TERM] => rxvt
    [SHELL] => /bin/bash
    [WINDOWID] => 31457282
...etc...

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-04-30 19:58 UTC] derick@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Oct 09 16:01:27 2024 UTC