Re: PHP eval() fatal error
| From: | Richard Lynch | Date: | Mon, 27 Aug 2007 03:40:08 +0000 |
| Subject: | Re: PHP eval() fatal error | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-261346@lists.php.net to get a copy of this message | ||
On Mon, August 20, 2007 8:54 am, 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?
I would expect that you need to wrap the try catch block *IN* the code
to be eval'd...
You sound like you know what you're doing, but I'm still gonna say it:
If eval is the solution, you probably didn't understand the problem. :-)
--
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?