Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations danielledunham on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Wrong line numbers in parse error display

Status
Not open for further replies.

papyG

Programmer
Joined
Aug 12, 2004
Messages
8
Location
CH
I'm using Php 4.3.6 (entropy release) under MacOs X 10.3.5.

When I get a Parse error such as
Parse error: parse error, unexpected T_ELSE in /Users/.../myfile.php on line 230
the error is actually some lines below (the increment is not constant)

I edit my files with BBedit Lite 6.1.2.

Before (using the official Php of a MacOs X Server (10.2.3)) I did not have this problem…

Who could help me with this topic ?
 
By "some lines below", do you mean "in the script in before the line (a lower line number) than where the error is reported"?

If so, this is because PHP isn't reporting where the error is, but rather the place at which it realized that your code stopped making sense to it. The actual error can reside many lines earlier in the script.


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
the error your getting is just caused by the syntax not making sense to the zend engine. If you write your code in the "right" way, the zend engine can stay happy for quite awhile until it finally hits some place where it goes huh? So, in other words, I agree with sleipnir214, I just thought his answer was a little bit unclear ("in the script in before the line")
 
Thanks for your your hint.

To be clear, if I write the following line :
if echo "aaa";
on line 57, I get the message :
Parse error: parse error, unexpected T_ECHO, expecting '(' in /Users/…/myfile.php on line 54

If I put the same instruction at say line 203, php sees the error at line 199 (or even lower…)

I'm working in a french environment and (see preceeding thread) I have also problems with special characters (with accents)

 
I am sure you know the actual error:
Code:
id [COLOR=red]([/color]condition[COLOR=red])[/color] execute...

The circumstances of the preceding lines makes the ZEND engine output the line number where it cannot make any more sense of what is going on. (Ok, I know I am the third person saying that).
 
I knew that before !

But when I write
if echo "aaa";
the zend machine stops at this line, for after "if " it expects a "(", doesn't it ?

Anyway, I'm sure Zend didn't behave this way before !
 
papyG:
Assuming that no earlier line in your script has an error, you will get the parse error at the line which contains the if-statement with the missing parentheses. (Yes, they are required.)

But if an earlier line of code contains a syntactic error, too, there is no guaranty that PHP will report an error on the line with the if-statement.


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Here is the solution of the mystery (or part of) :

I had to choose "Unix line breaks (0A)" in BBedit !

Another work around is (with 0D line break):
- start each line with a blank or a tab
- put a blank after a line containing only [tt]?>[/tt]
So, as most of my lines started with a tab, there was only a small difference between the error line number and the actual position of the error in the file.

But why is it sufficient to put a tab at the beginning of the line ?!
 
It probably has to do with the way PHP determines the end of a line.

This relates to the fact that Microsoft, Unix, and Apple have different ideas how to end a line. Microsoft uses "<carriage return><line feed>", Unix "<line feed>" and Apple "<carriage return>".

By placing whitespace at the beginning of the line, the parser will then try to parse the previous line.




Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top