Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

PHP error handling

Options
  • 07-06-2008 1:18am
    #1
    Registered Users Posts: 4,475 ✭✭✭


    I've got a class that handles my errors, and it seems to work okay. However, I have most of my content in include files and if it comes across an error in there, it appears to bubble back up, and not show the file or line that caused the error. For example:

    File A (includes error handler class)
    Line 40: include B.php

    File B
    Line 80: use a variable that doesn't exist (this is USER_NOTICE type error if that makes any diff)

    However, when this error is handled, it only shows A.php line 40. I'm putting the debug_backtrace into an array and printing that out gives me:
    Array
    (
        [0] => Array
            (
                [file] => A.php
                [line] => 40
                [args] => Array
                    (
                        [0] => B.php
                    )
    
                [function] => include_once
            )
    
    )
    
    So I can see the included file in the args array but no line number. If I change the included file so that it contains functions that I call from A.php, I get
    Array
    (
        [0] => Array
            (
                [file] => A.php
                [line] => 40
                [function] => display
                [args] => Array
                    (
                    )
    
            )
    
    )
    
    No args value this time. It must be possible to trace the line number of the INCLUDEd file that raised the error, and I'm pretty sure it's something dumb I'm doing, but my google-fu is letting me down.


Comments

  • Closed Accounts Posts: 2,046 ✭✭✭democrates


    Are you passing in __FILE__ and __LINE__ manually? http://ie.php.net/language.constants.predefined


  • Registered Users Posts: 4,475 ✭✭✭corblimey


    democrates wrote: »
    Are you passing in __FILE__ and __LINE__ manually? http://ie.php.net/language.constants.predefined

    if I use __FILE__ and __LINE__ it works fine, but it seems to be a problem with the debug_backtrace command
    If inside a function, this lists the functions arguments. If inside an included file, this lists the included file name(s).
    Seems bizarre to me.

    I've since removed the backtrace functionality and am just using __FILE__ and __LINE__ - it's not perfect, but it's best I can do.


Advertisement