note 121190 added to function.eval
| From: | divinity76 at gmail dot com | Date: | Tue, 06 Jun 2017 09:35:47 +0000 |
| Subject: | note 121190 added to function.eval | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-209112@lists.php.net to get a copy of this message | ||
imo, this is a better eval replacement:
<?php
function betterEval($code) {
$tmp = tmpfile ();
$tmpf = stream_get_meta_data ( $tmp );
$tmpf = $tmpf ['uri'];
fwrite ( $tmp, $code );
$ret = include ($tmpf);
fclose ( $tmp );
return $ret;
}
?>
- why? betterEval follows normal php opening and closing tag conventions, there's no need to
strip
<?php?> from the source. and it always throws a ParseError if there was a
parse error, instead of returning false (note: this was fixed for normal eval() in php 7.0). - and
there's also something about exception backtraces
----
Server IP: 72.52.91.14
Probable Submitter: 85.164.47.108
----
Manual Page -- http://php.net/manual/en/function.eval.php
Edit -- https://master.php.net/note/edit/121190
Del: integrated -- https://master.php.net/note/delete/121190/integrated
Del: useless -- https://master.php.net/note/delete/121190/useless
Del: bad code -- https://master.php.net/note/delete/121190/bad+code
Del: spam -- https://master.php.net/note/delete/121190/spam
Del: non-english -- https://master.php.net/note/delete/121190/non-english
Del: in docs -- https://master.php.net/note/delete/121190/in+docs
Del: other reasons-- https://master.php.net/note/delete/121190
Reject -- https://master.php.net/note/reject/121190
Search -- https://master.php.net/manage/user-notes.php