note 77318 deleted from function.php-check-syntax by thiago

From: Date: Fri, 12 Dec 2008 11:40:34 +0000
Subject: note 77318 deleted from function.php-check-syntax by thiago
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-148067@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 (#148067) next »