Page 1 of 1
trigger_error - getting function call line
Posted: Sat Apr 28, 2007 3:48 am
by MikeG
I'm using trigger_error within a class, however the line PHP outputs is the line of code trigger_error() is called at within the class. Is there a way to get it to output the line the class function was called on, as well as the file? For example:
Code: Select all
class test
{
function myfunc()
{
trigger_error( 'My error message' ) // <-- I don't want this line
}
}
test::myfunc() // <--- would it be possible to return this line number?
If I have to abandon the trigger_error function that is fine, but I'd prefer similar functionality. Thanks for the help.
Re: trigger_error - getting function call line
Posted: Sat Apr 28, 2007 9:56 am
by Zu
MikeG wrote:Is there a way to get it to output the line the class function was called on, as well as the file? For example:
In a way.
__LINE__ and __FILE__.
Posted: Sat Apr 28, 2007 11:28 am
by MikeG
__LINE__ and __FILE__ also get the line and file they're placed on. I'm looking for something automatic like the PHP functions do.
Posted: Sat Apr 28, 2007 11:51 am
by John Cartwright
Posted: Sat Apr 28, 2007 5:06 pm
by MikeG
Was hoping I didn't have to use that, but I guess that's my only other option
Thanks for the help
Posted: Sun Apr 29, 2007 5:13 am
by rebus
I use costum function that takes 4 arguments in order:
error level
__FILE__
__LINE__
string error message
And then call trigger_error() from that function. You dont get the exact line number but it is very close to it, and costum error message usually makes things clear.
I also like to add a configuration check for development or debug status and if it is turned on use debug_backtrace() for debugging in same function.
makes my life a lot easier and plus you can control error message formating and stuff...
Posted: Sun Apr 29, 2007 5:18 am
by Ollie Saunders
Was hoping I didn't have to use that
It's not hard
Code: Select all
$backtrace = debug_backtrace();
$called = $backtrace[$howFarBack = 1];
return $called['file'] . ' on line ' . $called['line'];