php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #28290 Throwing exception in eval'led code is not handled correctly
Submitted: 2004-05-05 23:47 UTC Modified: 2005-01-22 01:00 UTC
Votes:2
Avg. Score:4.5 ± 0.5
Reproduced:2 of 2 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: arnoud at rattink dot com Assigned:
Status: No Feedback Package: Scripting Engine problem
PHP Version: 5.0.0RC2 OS: SuSE Linux 8.2
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: arnoud at rattink dot com
New email:
PHP Version: OS:

 

 [2004-05-05 23:47 UTC] arnoud at rattink dot com
Description:
------------
The code below prints GRRRRRRRR. This is incorrect as the 
throwing of the exception is supposed to bring us 
immediately to the catchblock. It is also inconsistent, 
since I can replace the eval with just  
$f = AAAAAARRRRRRRRG(); 
and then it skips the echo. 
 

Reproduce code:
---------------
<?
function AAAAAARRRRRRG(){
    throw new Exception("AAAAAARRRRRRG");
}

try {
    eval('$f = AAAAAARRRRRRG();');
    echo "GRRRRRRRR\n";
}
catch(Exception $e) {
    echo "Exception caught nice and clean\n";
}
?>

Expected result:
----------------
I do not expect to see GRRRRRRRR. 

Actual result:
--------------
GRRRRRRRR 
Exception caught nice and clean 
 

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-05-11 05:07 UTC] vkatragadda at email dot com
hello, i dont think this is a bug. i believe the line after eval gets executed by default. i think everything in the try{} block is supposed to get executed, and then the catch{} block is called...
 [2004-05-11 05:10 UTC] vkatragadda at email dot com
hello, i dont think this is a bug. i believe the line after eval gets executed by default. i think everything in the try{} block is supposed to get executed, and then the catch{} block is called...
 [2004-05-14 00:01 UTC] arnoud at rattink dot com
That is not true. Example: 
 
<? 
function f() { throw new Exception("I am an exception"); 
} 
 
try 
{ 
    $v = f(); 
    echo "This is not supposed to get printed\n"; 
} 
catch(Exception $e) { 
    echo "caught exception\n"; 
} 
?> 
 
This just prints 'caught exception'. That is entirely 
correct. Now if you were right, then the above code should 
execute both echos. It does not, so is that a bug? I say 
it's a catch 22. 
 
Either this program, or the one with the 'eval' works out 
wrong. Personally I believe the whole idea of 'throwing an 
exception' is that you bypass all intermediate code and 
land straight into the 'catch' block. At least, that's how 
it works in C++ and Java.
 [2005-01-15 00:23 UTC] tony2001@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5-STABLE-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5.0-win32-latest.zip

Can't reproduce, seems to be fixed.
 [2005-01-22 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 [2009-10-08 12:41 UTC] cedric at conseil-creation dot com
Don't think it's a bug... just read the following not in PHP.NET eval manual:

"If there is a parse error in the evaluated code, eval() returns FALSE and execution of the following code continues normally."

What about this code (?!):
---------------------------
    if ( eval('$f = AAAAAARRRRRRG();') )
    {
        echo "GRRRRRRRR\n";
    }
---------------------------

Or this one:
---------------------------
    if ( !eval('$f = AAAAAARRRRRRG();') )
    {
    // parse error
    }
    echo "GRRRRRRRR\n";
    }
---------------------------
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sun May 11 13:01:28 2025 UTC