note 117765 deleted from function.eval by googleguy
| From: | googleguy@php.net | Date: | Fri, 24 Feb 2017 21:07:05 +0000 |
| Subject: | note 117765 deleted from function.eval by googleguy | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-208810@lists.php.net to get a copy of this message | ||
Note Submitter: turboflash
----
Sharing a code which might be useful to someone. my_eval() is useful if
- You don't want to introduce new variables like what eval() would do.
- You just want to execute some calculations or some file/database retrieval and return the result.
- By returning the result in an array, you can differentiate a FALSE between a parse error or a
result returned by the $code.
function my_eval($code) {
$my_code = '$my_function = function () {' . $code . '}; return
array($my_function());';
return eval($my_code);
}