note 80370 added to function.php-check-syntax

From: Date: Sat, 12 Jan 2008 07:51:02 +0000
Subject: note 80370 added to function.php-check-syntax
Groups: php.notes 
Request: Send a blank email to php-notes+get-135052@lists.php.net to get a copy of this message
Nicolas' code is great! Just another check to make sure a } doesn't come before { and it's much more secure. Still wouldn't trust just anyones code with it though. <?php function eval_syntax($code){ $b = 0; foreach (token_get_all($code) as $token){ if('{' == $token){ ++$b; }elseif('}' == $token){ --$b; if( $b < 0 ){ return false; // } came before { } } } // Unbalanced braces would break the eval below if( $b !== 0){ return false; } // Catch potential parse error messages ob_start(); $code = eval('if(0){' . $code . '}'); // Put $code in a dead code sandbox to prevent its execution ob_end_clean(); return false !== $code; } ---- Server IP: 208.69.120.35 Probable Submitter: 71.34.146.218 ---- Manual Page -- http://www.php.net/manual/en/function.php-check-syntax.php Edit -- https://master.php.net/note/edit/80370 Del: integrated -- https://master.php.net/note/delete/80370/integrated Del: useless -- https://master.php.net/note/delete/80370/useless Del: bad code -- https://master.php.net/note/delete/80370/bad+code Del: spam -- https://master.php.net/note/delete/80370/spam Del: non-english -- https://master.php.net/note/delete/80370/non-english Del: in docs -- https://master.php.net/note/delete/80370/in+docs Del: other reasons-- https://master.php.net/note/delete/80370 Reject -- https://master.php.net/note/reject/80370 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#135052) next »