Why doesn't lint tell me the line number and nature of the parse error?
I'm calling php lint from a Windows batch file, like so:
@echo off
for %%f in (*.php) do php -l %%f
When a file contains a syntax error, it only outputs Erro开发者_StackOverflow社区rs parsing xxx.php
. Is there any way to get it to tell me what the nature of the error is, and what line it's on? Maybe another switch?
If you get the "Errors parsing foo.php" message without any details, this parameter shows errors when you run PHP lint:
php -d display_errors=1 -l foo.php
Example:
[somewhere]# php -l submit.php Errors parsing submit.php [somewhere]# php -d display_errors=1 -l submit.php Parse error: syntax error, unexpected T_VARIABLE in submit.php on line 226 Errors parsing submit.php
I've accepted Charles's answer, but thought I should add a couple of details, as I had to do some extra hunting to find out what to do.
The problem was that I wasn't seeing the stderr
output, so I started by adding 2>&1
to the end of the relevant commands. This still didn't help, so I realised that the problem was that PHP wasn't outputting stderr stuff at all. I went to the PHP install directory and looked in php.ini and found that by default, display_errors
is Off
. Changed it to On
and it now works.
What version of PHP are you using? As of 5.3, line numbers are included in lint output:
[charles@server ~]$ cat syntax_error.php
<?php
echo "This line is legal\n";
echo I'm a syntax error!\n;
echo "This line never gets reached.\n"
[charles@server ~]$ php -l syntax_error.php
PHP Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting ',' or ';' in syntax_error.php on line 3
Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting ',' or ';' in syntax_error.php on line 3
Errors parsing syntax_error.php
[charles@server ~]$
The error appears twice because it's going to both stdout and stderr. It's been a long time since I've worked with batch files on Windows, maybe the version you're using only emits the error on stderr, and the batch file is discarding the output of stderr?
精彩评论