Re: PHP eval() fatal error

From: Date: Mon, 20 Aug 2007 14:12:48 +0000
Subject: Re: PHP eval() fatal error
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-261050@lists.php.net to get a copy of this message
Maarten Balliauw wrote:
Here's the thing: I'm trying to do some dynamic code compilation within PHP using eval(). The code I'm trying to compile raises an E_ERROR (Fatal). Here's a simple example: <?php $code = ' $returnValue = 12*A+; '; // Clearly incorrect code :-) $returnValue = 0; eval($code); ?> Now, I'd like to catch the error made by eval: // ... try { eval($code); } catch (Exception $ex) { var_dump($ex); } // ... Problem persists: a fatal error occurs. Using set_error_handler() and set_exception_handler() is not working either... Is there any way to gracefully catch this error? Regards, Maarten
If you read the manual (RTFM) at http://www.php.net/eval you'll notice the following: " If there is a parse error in the evaluated code, eval() returns FALSE and execution of the following code continues normally. It is not possible to catch a parse error in eval() using set_error_handler(). Note: In case of a fatal error in the evaluated code, the whole script exits. " So, no.

« previous php.general (#261050) next »