php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #48830 eval() parser error/warning on \'
Submitted: 2009-07-07 09:23 UTC Modified: 2009-07-07 11:32 UTC
From: s dot coletta at unidata dot it Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.2.10 OS: Windows/Ubuntu
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: s dot coletta at unidata dot it
New email:
PHP Version: OS:

 

 [2009-07-07 09:23 UTC] s dot coletta at unidata dot it
Description:
------------
Eval() makes a wrong parsing of a string ending with \\' or \'

The "Reproduce code" will not fail if you remove the ending \\ or \ like:

$str = "define('A','C:\\Dir');"; or
$str = "define('A','C:\Dir');";


Reproduce code:
---------------
$str = "define('A','C:\\Dir\\');";
eval($str);

or 

$str = "define('A','C:\Dir\');";
eval($str);


Expected result:
----------------
No warnings or errors.

Just this statement executed:

define('A','C:\Dir\');


Actual result:
--------------
For both examples provided the result is the same:


Warning: Unexpected character in input: ''' (ASCII=39) state=1 in /test.php(3) : eval()'d code on line 1

Parse error: syntax error, unexpected ':' in /test.php(3) : eval()'d code on line 1

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-07-07 09:43 UTC] sjoerd-php at linuxonly dot nl
Thank you for your bug report.

The issue you report is not a bug. Both strings in your example look like this:
define('A','C:\Dir\');

Note that the last single quote is escaped by the backslash. Passing this to eval or putting this string in a PHP file will rightfully give a parse error, because there is no ending quote.
 [2009-07-07 10:38 UTC] s dot coletta at unidata dot it
I'm sorry but if I write this code:

$str = "define('A','C:\\Dir\\');";
eval($str);

I expect to be evaluated properly because \\' has to be escaped to \'

So you are saying that: \\' is escaped to \' by the PHP parser when assigned to the string $str then eval parses it again escaping \' a second time and causing the error.

Now, if I need to eval a statement like that, and this is not considered a bug, how can I workaround this?
 [2009-07-07 11:32 UTC] jani@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

http://php.net/eval
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Mon Jul 28 04:00:02 2025 UTC