php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #15241 eval() is not allow evaluating code from constants
Submitted: 2002-01-27 06:46 UTC Modified: 2002-07-31 09:25 UTC
Votes:1
Avg. Score:1.0 ± 0.0
Reproduced:0 of 1 (0.0%)
From: flying at dom dot natm dot ru Assigned: hholzgra (profile)
Status: Not a bug Package: Scripting Engine problem
PHP Version: 4.1.1 OS: all
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: flying at dom dot natm dot ru
New email:
PHP Version: OS:

 

 [2002-01-27 06:46 UTC] flying at dom dot natm dot ru
 Check out these simple examples:

Example 1:
-----------------------------------------------------
<?php
function getCode()
{
    return("echo 'hello world!';");
};

eval(getCode());
?>
-----------------------------------------------------

 Result of executing whis example will be a string 'hello world!' as expected.

Example 2: 
-----------------------------------------------------
<?php
define('PHP_CODE','getCode()');

function getCode()
{
    return("echo 'hello world!';");
};

eval(PHP_CODE);
?>
-----------------------------------------------------

 As you can see - i just move code from eval() into constant
and substitute it with constant name instead of actual code into eval() statement.

 But result of executing this example is:

Parse error: parse error in test.php(9) : eval()'d code on line 1

 Tested with both 4.0.6 and 4.1.1 on windows 2000 and linux.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-06-17 17:01 UTC] hholzgra@php.net
yet another locale dependant ZE bug only affecting
non-latin locales (like cyrillic)

for now either use lowercase constants 
or setlocale(LC_ALL, "C")
 [2002-07-31 09:25 UTC] iliaa@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

if you add a ; to the 
define('PHP_CODE','getCode()');
so it looks like this:
define('PHP_CODE','getCode();');
the parse error will go away.

You are also trying to do a double eval, which is imposible to do.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sun May 11 08:01:28 2025 UTC