I am having a very frustrating problem, and I hope someone can point me in the right direction.

PHP consistently reports the wrong line number for errors. The line number it reports is usually about 30 lines before where the error actually is. As you can imagine, this makes debugging very difficult.

This is PHP 4.0.3pl1 running on Windows NT. I usually use PHP on Unix, and I've never had this problem before.

Any suggestions are greatly appreciated!

    Well.. This all depends on what type of error you are dealing with:

    <?php
    function something() {
    // do function stuff
    // }

    if ($criteria) {
    // 300 lines of code
    }

    ?>

    The php compiler would now think the error is at the end of the file, because you forgot a finishing '}' for the function. The if-test is supposed (in your head) to be outside the function, but how is php supposed to know that?

    However, an error such as;

    <?php
    // 200 lines of code
    print "hi';
    // 50 lines of code
    ?>

    would most likely give you a very accurate line number.

    In other words, if this is a problem, you should, in case you don't, use indenting. And using a "real" programmers editor like emacs or vi, you can make some nifty cursor movements. (E.g. when you type }, the cursor automatically jumps to the corresponding { for a brief second. Same goes for paranthesis and so on).

    If these kind of things happen to me, I usually comment out large chunks of the code, and if the error persists, i remove comments, comment out another chunk, etc. This way, I can (realtively and usually) locate it.

      Thanks for the response, but I don't think that's the problem. I've created a new thread, because this is actually a slightly different problem than I thought it was.

        2 months later

        If using Frontpage and shared borders then the line number will be wrong. Frontpage extensions deal with shared borders and viewing the HTML within FP won't show the code for the borders too.

        However PHP does get passed the additional HTML of the shared borders and so although it appears your error line numbers are wrong - they're not.

        Try either getting a utility (generally a PHP file which takes a PHP filename as a parameter and displays the actual page - do an internet search for source.php) which will display the page that's delivered to the PHP pre-processor - shared border code inclusive, or better still debug with shared borders turned off. That's what I do.

        Of course if you ain't using FP then I just wasted my time!

          Write a Reply...