When using the php -l myFile.php
command (PHP 5.5.30), if the file has a syntax error then I get the proper warnings and stack trace, etc.
However, if the file has no syntax warnings I get the message
No syntax errors detected in myFile.php
Is there a way to have the command have no output when the syntax is valid? I only care if a file has invalid syntax - I don't need a message saying it's valid.
The "no syntax errors..." message is sent out on the stdout
while the syntax errors are sent out on stderr
. You can redirect those to somewhere like /dev/null
if you don't want them.
php -l file.php 1> /dev/null
that will output the errors if there were any or nothing if no errors. You do lose the "Errors parsing..." message, but will get the errors if there was a problem.