Check a PHP file for syntax errors -
i'm attempting build auditing feature application check various code quality issues.
one of things check php files syntax errors. going use php_check_syntax() has been removed in php 5.0.5.
i've tried using exec()
statements isn't outputting anything. i've added date
make sure exec()
working:
<?php error_reporting(e_all | e_notice | e_strict | e_warning); ini_set('display_errors', 1); $output = 'before'; var_dump($output); var_dump(exec('php -l ' . __file__, $output)); var_dump($output); var_dump(exec('date', $output)); var_dump($output);
output:
string 'before' (length=6) string '' (length=0) array (size=0) empty string 'thu feb 6 10:42:35 pst 2014' (length=28) array (size=1) 0 => string 'thu feb 6 10:42:35 pst 2014' (length=28)
how can check php file syntax errors in php?
check web-server configuration. places this: disable_functions="". after var_dump($output) starts return array check errors in array eliminate further errors correct path php.
use eliminate other possibilities:
$output="just before exec"; var_dump($output); exec('php -l /path/to/file.php', $output); var_dump($output);
p.s. may used
echo exec('php -l /path/to/file.php');
upd: updated question shows exec works. may *nix platform hides error output. way redirect add command 2>&1 redirect error output standard output
$to_run = '/path/to/bin/php -l /path/to/file 2>&1'; $output ="" ; //init var_dump(exec($to_run, $output));
if have root access on platform may use tools strace debug complicated cases.
'/path/to/bin/strace -o/path/to/strace.log php -l /path/to/file.php'
upd: var_dump(exec('php -l ' . file .' 2>&1', $output)); // error redirection unix platform
Comments
Post a Comment