[UPHPU] Syntax errors now causing script termination

Fred Larsen fred at bitwyze.com
Sun Apr 11 23:12:08 MDT 2004

Your include file could use set_error_handler to set a user-defined error
handler function. 

On Sun, 11 Apr 2004, David Smith wrote:

> In phpLDAPadmin, I do some fancy syntax checking with ob_start(), 
> include(), and ob_get_contents() to check for syntax errors in the user 
> configuration file. The config file is actually a PHP file, so I just 
> include() it in the app directly. Under PHP 4.1 and 4.2, I can do this 
> and successfully detect a syntax error:
> ob_start();
> include 'config.php';
> $str = ob_get_contents();
> ob_end_clean();
> if( $str && false !== strpos( $str, 'error' ) )  {
>     echo "Config file has errors...";
>     $matches = array();
>     preg_match( "/on line (\d+)/", $str, $matches );
>     $line_num = $matches[1];
>     // More fancy stuff to display the error to the user...
> }
> You can see this in action here: 
> http://cannons.dsl.xmission.com/~dsmith/phpldapadmin-devel/
> However, under PHP 4.3.5, it appears that when I include() a PHP file 
> with syntax errors (the most common kind in my case), script execution 
> terminates! This is not the behavior I want nor does it seem consistent 
> with PHP's documentation, so now I am searching for some way to cleanly 
> check the syntax of a PHP file that is not so kludgy and works with PHP 
> 4.*.*. It must be OS-independent as phpLDAPadmin is deployable on 
> Windows, BSD, Linux, Mac, etc. It must also not rely on *any* special 
> php.ini settings, as phpLDAPadmin will work with any php.ini configuration.
> So, anyone have any ideas?
> --Dave
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: list-unsubscribe at uphpu.org
> For additional commands, e-mail: list-help at uphpu.org


More information about the UPHPU mailing list