note 81376 added to function.eval
| From: | Ipseno at yahoo dot com | Date: | Mon, 25 Feb 2008 18:24:25 +0000 |
| Subject: | note 81376 added to function.eval | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-136475@lists.php.net to get a copy of this message | ||
If you attempt to call a user defined function in eval() and .php files are obfuscated by Zend
encoder, it will result in a fatal error.
Use a call_user_func() inside eval() to call your personal hand made functions.
This is user function
<?php
function square_it($nmb)
{
return $nmb * $nmb;
}
?>
//Checking if eval sees it?
<?php
$code = var_export( function_exists('square_it') );
eval( $code ); //returns TRUE - so yes it does!
?>
This will result in a fatal error:
PHP Fatal error: Call to undefined function square_it()
<?php
$code = 'echo square_it(55);' ;
eval( $code );
?>
This will work
<?php
$code = 'echo call_user_func(\'square_it\', 55);' ;
eval( $code );
?>
----
Server IP: 69.147.83.197
Probable Submitter: 82.193.208.173
----
Manual Page -- http://www.php.net/manual/en/function.eval.php
Edit -- https://master.php.net/note/edit/81376
Del: integrated -- https://master.php.net/note/delete/81376/integrated
Del: useless -- https://master.php.net/note/delete/81376/useless
Del: bad code -- https://master.php.net/note/delete/81376/bad+code
Del: spam -- https://master.php.net/note/delete/81376/spam
Del: non-english -- https://master.php.net/note/delete/81376/non-english
Del: in docs -- https://master.php.net/note/delete/81376/in+docs
Del: other reasons-- https://master.php.net/note/delete/81376
Reject -- https://master.php.net/note/reject/81376
Search -- https://master.php.net/manage/user-notes.php