note 77319 deleted from function.eval by ezyang

From: Date: Wed, 03 Oct 2007 01:25:50 +0000
Subject: note 77319 deleted from function.eval by ezyang
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-131013@lists.php.net to get a copy of this message
Note Submitter: nicolas dot grekas+php at gmail dot com ---- 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; } } ?>

« previous php.notes (#131013) next »