Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP error line numbers completely off

I don't know what's going on with my PHP. I'm using a bunch of classes and a semi-MVC framework that I developed myself (as an experiment). So the PHP file is including a lot of class files.

My PHP line numbers for error messages are completely off and therefore useless and making it impossible for me to debug. For example, right now I'm getting an error message that says:

`Parse error: syntax error, unexpected ')' in /view.php on line 209

The only problem is: there is no ')' anywhere near line 209. Even worse, if I put die() on line 200 or so, it still gives me an error message, now pushed down to line 210. So clearly the line of code is being taken into account, yet for some reason it's not dying.

Another thing is, it's including a header.php file prior to this line. The header file basically just outputs some HTML, and works fine on other pages. Yet on this page, it doesn't even output the header; it's just dying with a blank page and that error message.

Is there anything I can do to use more reliable debugging? If I could have an accurate line number, I'm sure I'd find the bug easily.

Edit: I found the bug. The point of this question is not to solve the unexpected ')' bug. The point is: why are the line numbers inaccurate? The actual error message was on line 218, not 209 or 210.

like image 961
andrewtweber Avatar asked May 19 '11 05:05

andrewtweber


People also ask

How do I turn off PHP error reporting?

To turn off or disable error reporting in PHP, set the value to zero. For example, use the code snippet: <? php error_reporting(0); ?>

How do I get PHP errors to display?

To Show All PHP Errors Adding these lines to your PHP code file is the quickest way to output all PHP errors and warnings: ini_set ('display_errors', 1); ini_set ('display_startup_errors', 1); error_reporting (E_ALL); The ini_set() function will attempt to override the PHP ini file's configuration.

What causes PHP fatal error?

PHP Fatal Errors are coding errors so severe that the server cannot display the site properly - they are usually caused by conflicting or poorly designed extensions, . htaccess misconfigurations and things like that.


1 Answers

It's your line endings. Open up a program where you can change the line endings and change it to that of the server and the line number will be correct. I don't know about windows, but on mac you can change line endings using TextWrangler (or BBEdit) and on linux using gedit.

like image 102
None Avatar answered Sep 25 '22 02:09

None