php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #11962 eval() doesn't handle multi-dimentional arrays.
Submitted: 2001-07-08 20:00 UTC Modified: 2001-07-09 07:37 UTC
From: karl at kdawebservices dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 4.0.6 OS: RedHat 6.2
Private report: No CVE-ID: None
 [2001-07-08 20:00 UTC] karl at kdawebservices dot com
It appears that eval() does not handle mutli-dimentional arrays properly e.g.

$page[title] = 'Page';
$test = '$page[title]';

If I do:

eval( 'echo "'.$test.'";' );

I get:

Page

as the output, however if I change $test to:

$test = '$GLOBALS[page][title]';

then do:

eval( 'echo "'.$test.'";' );

I get:

Array[title]

as my output.

My best guess for the reason this is happening is that when eval() does a lookup for a variable in the symbol table it is going from top to bottom and stops on the first match, no matter how complete - From this I am assuming that the symbol table would be built as follows:

$GLOBALS
$GLOBALS[page]
$GLOBALS[page][title]

so if eval() searched from the top then it would find a partial match against $GLOBALS[page] which is what I think it is doing.

A better example:

    $page[title] = 'Hello';

    $string = '$page[title]';
    eval( 'echo "'.$string.'";' );

    echo "<br>\n";

    $string = '$GLOBALS[page][title]';
    eval( 'echo "'.$string.'";' );


I hope I make sense to you, if not then please let me know and I will try and be clearer.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-07-09 07:08 UTC] jeroen@php.net
Your string equals 


'echo "$GLOBALS[page][title]";', and RTFM why that doesn't work.
 [2001-07-09 07:37 UTC] derick@php.net
Because the parser ain't smart enough, try echo $GLOBALS['page']['id']; or echo "{$GLOBALS['page']['id']}"; (the first one is faster).

Derick
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 26 08:01:30 2024 UTC