note 32952 added to function.eval
| From: | gk at proliberty dot com | Date: | Wed, 11 Jun 2003 19:48:57 +0000 |
| Subject: | note 32952 added to function.eval | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-50200@lists.php.net to get a copy of this message | ||
eval() returns FALSE if a fatal error occurs.
For this reason, you should never return() a FALSE value from eval()'d code or else you will
lose the distinction between FALSE and FATAL.
Note also that if you have installed a custom error handler, with set_error_handler(), it will NOT
be used to handle errors inside your eval() statement. You can call
eval("set_error_handler('myErrorHandler'); //...") but Parse and other Fatal
errors that NEVER are passed to a custom error handler will still always result in FALSE being
returned from eval().
Sample code:
<?php
// FILE: test/test.php
$x=eval(";");
echo "Default Return Value: ";
if($x===FALSE) echo "FALSE\n";
if(is_null($x)) echo "NULL\n";
$x=eval("<?");
echo "Fatal Error Returns: ";
if($x===FALSE) echo "FALSE\n";
if(is_null($x)) echo "NULL\n";
?>
OUTPUT:
$ php test/test.php
Default Return Value: NULL
PHP Parse error: parse error in
/usr/local/apache/htdocs/common/php/xmake_org/xobj/test/test.php(6) :
eval()'d code on line 1
Fatal Error Returns: FALSE
----
Manual Page -- http://www.php.net/manual/en/function.eval.php
Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+32952
Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+32952&report=yes
Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+32952&report=yes