|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2003-02-24 08:11 UTC] tom dot polak at post dot cz
Hello,
First, I have found similar request as #13944,
but there is NO SOLUTION EXPLAINED, only closed.
If this request is solved, then my request is solved too,
but how was #13944 solved?
I am trying to write error handler function as follows:
function ErrorHandler($msg,$file=__FILE__,$line=__LINE__){
print("Error {$msg} in file {$file} on line {$line}\n");
}
which can be called from any php script when error occurs:
...
if($somethingwrong){
ErrorHandler("something wrong");
}
I can to see the $file and $line pointing to the place,
from which is ErrorHanlder function called.
But currently I see allwys the same file and line
of the ErrorHandler function itself.
This request is based on big amount of php script files,
where is not so simple to found, where the error condition
occurs. Because the $msg itself is often not enough to
explain the point in source code.
Secondary, I need to have own errorhandler, because
using some features when the error appears in SQL command,
there is more additional information displayed (not
showed in example above, because is not relevant to this request). I am logging errors by its type to several
locations, conditionally email it to response admin
and other things.
Because of hunderts calls of ErrorHandler, using __FILE__
and __LINE__ is very time and place consuming.
With hope, that this description is understandable,
even my poor english knowledge.
Best regards,
Tomas Polak
tom.polak@post.cz
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 29 14:00:01 2025 UTC |
This should have been posted as a comment to the original (fixed) bug, not opened as a new bug, therefor this needs to be flagged as 'Bogus'. The Comment listed with closing states to use debug_backtrace() to get these values... In your case try the following: function my_function($msg, $file=false, $line=false) { $bt = debug_backtrace(); if (!$file) $file = $bt[0]['file']; if (!$line) $line = $bt[0]['line']; /* Do your thing */ }