Re: [PHP] Re: PHP eval() fatal error

2007-08-27 Thread Richard Lynch
On Mon, August 27, 2007 12:59 am, Maarten Balliauw wrote:
> Now let's repeat my question: is there any way to gracefully evaluate
> specific code, eventually catch an error and respond to that, without
> using parsekit() or launching another process to get this done?

I missed that you had an E_ERROR parse error.  Sorry.

To answer your question:

No.



You may want to look at various testing frameworks for PHP such as
php_unit and the "make test" of PHP itself to see how they run tests
such that syntax errors in individual tests don't halt the whole
process.

I know for sure the PHP make test fires off a separate PHP process.

Keep in mind that you're asking PHP to try to execute code that it
can't even parse to start with...  Rather like expecting to get an
a.out from a C program that doesn't compile.  Not gonna happen.

-- 
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?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: PHP eval() fatal error

2007-08-26 Thread Maarten Balliauw
When re-writing this example to a form of "create_function", the same 
problem occurs:


	$temporaryCalculationFunction = @create_function('', $code); // E_ERROR 
here

if ($temporaryCalculationFunction === FALSE) {
$returnValue = '#N/A';
} else {
   		$returnValue = call_user_func_array($temporaryCalculationFunction, 
array());

}
} catch (Exception $ex) {
$returnValue = '#N/A';
}
?>

Now I would expect that when I feed "create_function" invalid code 
(syntax), the function returns false. It doesn't!


E_ERROR is thrown right away. In my opinion, this should return FALSE, 
and only throw an E_ERROR when the created function is executed...


Before telling me to read the manual: I did over a hundred times, on 
both eval and create_function: create_function is not documented to 
throw E_ERROR right away, instead returning FALSE on error... Exactly 
what I was thinking using the above code.


Now let's repeat my question: is there any way to gracefully evaluate 
specific code, eventually catch an error and respond to that, without 
using parsekit() or launching another process to get this done?


Regards,
Maarten

PS: Eval/create_function is in place in my code, I don't see any other 
method to execute (filtered, of course !!!) PHP code that is embedded in 
a string.



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:



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


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: PHP eval() fatal error

2007-08-20 Thread M. Sokolewicz

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:



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.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php