Re: Display line-numbers of funktion calls?
| From: | Philip Olson | Date: | Fri, 11 Apr 2003 22:25:28 +0000 |
| Subject: | Re: Display line-numbers of funktion calls? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-143583@lists.php.net to get a copy of this message | ||
> > does anyone know a way to get the file and line number of a function call
> > within the called function?
> > I use a self-written class for database-abstraction (for easily changing the
> > databse-type) and when i get a sql-error, the scripts are only displaying
> > the line number of the include-file with the class, wich complicates
> > debugging quite much.
>
> This is not possible before PHP 4.3. Using __FILE__ and __LINE__ will
> only give you what you're already getting, not what called it. PHP 4.3
> provides the debug_backtrace() function, which will give you this
> information in a big stack array.
>
> Have a look at http://www.php.net/debug_backtrace
Many times people pass in the __LINE__ and __FILE__ to their
error handling function which yes can be a little tedious
but it's how it is. Something like:
if (error) {
db_error("Bad Stuff", __LINE__, __FILE__);
}
This way the error handler will have the proper information.
On a related note, as of 4.3.0 we now have __FUNCTION__
and __CLASS__ available.
Regards,
Philip