RE: [PHP] Parsing PHP code from PHP

From: Date: Tue, 08 Apr 2003 20:19:49 +0000
Subject: RE: [PHP] Parsing PHP code from PHP
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-142953@lists.php.net to get a copy of this message
The problem is that eval does execute the code, I want to parse for errors without executing the code. -----Original Message----- From: Ernest E Vogelsinger [mailto:ernest@vogelsinger.at] Sent: Tuesday, April 08, 2003 5:18 PM To: luis Cc: php-general@lists.php.net Subject: Re: [PHP] Parsing PHP code from PHP At 21:57 08.04.2003, luis said: --------------------[snip]-------------------- >I'm writing an application where the user can edit PHP scripts that are >later executed. >(All the security considerations can be supressed in replies) >I want to know if you know some PHP parser in PHP that could be used to >parse the scripts and inform the user if there're parsing errors in the >scripts they edited. >Using the PHP command line tool is not an option. --------------------[snip]-------------------- .k, no security ;-> Just use eval() and capture the error output from the evaluated script: global $php_errormsg; $errmsg = null; $result = @eval($code); $errmsg = $php_errormsg; if ($errmsg) { // display error - could also be a warning! } else { // display $result or proceed elsewhere } Take care that _any_ output PHP generates will show up in $php_errormsg. Any error or warning will overwrite the next instance, hence the immediate assignment to another variable after eval() returns. I believe you could use your own error handler to be more granular in this situation. -- >O Ernest E. Vogelsinger (\) ICQ #13394035 ^ http://www.vogelsinger.at/

« previous php.general (#142953) next »