Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why doesn't lint tell me the line number and nature of the parse error?

Tags:

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 Errors 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?

like image 766
Hammerite Avatar asked Jul 27 '10 00:07

Hammerite


People also ask

What is the parse error?

A parse error is an error message you sometimes get on Android devices when an app fails to install. The message itself is not very specific, and there are a lot of problems that can cause it.

What happens if a function is placed in a lint library?

No error occurs if a symbol in the LINT library has the same name as a symbol in the source file; the source file symbol is the one that is used. Functions should only be placed in a LINT library when you are sure they contain no errors.

Why am I getting a lint error when writing inline functions?

This message comes up when trying to write inline functions without giving the function a name. Lint is set to avoid anonymous functions because giving names is more readable. Here is an example;

How does lint check for syntax errors?

When LINT creates a Summary file, LINT only summarizes your source code and checks for syntax errors. It does not check for such problems as non-portable constructs or type mismatches. However, you can run a summary file through LINT again to do standard type-checking.

What happens if you use the wrong event type in Lint?

This one can happen easily making a mistake and using the wrong event type. It won’t create a compile-time error, but lint will find the error or properties won’t be available.


2 Answers

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
like image 100
PJ Brunet Avatar answered Sep 19 '22 18:09

PJ Brunet


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.

like image 43
Hammerite Avatar answered Sep 19 '22 18:09

Hammerite