I'm attempting to build an auditing feature into my application that will check for various code quality issues.
One of the things I would like to do is check certain PHP files for syntax errors. I was going to use php_check_syntax() but it has been removed in PHP 5.0.5.
I've tried using exec()
statements but it isn't outputting anything. I've added a date
to make sure exec()
is 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 I check a PHP file for syntax errors in PHP?