note 77319 added to function.eval
| From: | nicolas dot grekas+php at gmail dot com | Date: | Fri, 24 Aug 2007 11:24:38 +0000 |
| Subject: | note 77319 added to function.eval | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-129748@lists.php.net to get a copy of this message | ||
This detects parse errors without executing the code:
<?php
function eval_syntax($code)
{
$b = 0;
foreach (token_get_all($code) as $token)
{
if ('{' == $token) ++$b;
else if ('}' == $token) --$b;
}
if ($b) return false; // Unbalanced braces would break the eval below
else
{
ob_start(); // Catch potential parse error messages
$code = eval('if(0){' . $code . '}'); // Put $code in a dead code sandbox to
prevent its execution
ob_end_clean();
return false !== $code;
}
}
?>
----
Server IP: 217.174.196.197
Probable Submitter: 82.239.245.173
----
Manual Page -- http://www.php.net/manual/en/function.eval.php
Edit -- https://master.php.net/note/edit/77319
Del: integrated -- https://master.php.net/note/delete/77319/integrated
Del: useless -- https://master.php.net/note/delete/77319/useless
Del: bad code -- https://master.php.net/note/delete/77319/bad+code
Del: spam -- https://master.php.net/note/delete/77319/spam
Del: non-english -- https://master.php.net/note/delete/77319/non-english
Del: in docs -- https://master.php.net/note/delete/77319/in+docs
Del: other reasons-- https://master.php.net/note/delete/77319
Reject -- https://master.php.net/note/reject/77319
Search -- https://master.php.net/manage/user-notes.php