php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #22393 __FILE__, __LINE__ as default parameter value
Submitted: 2003-02-24 08:11 UTC Modified: 2003-03-13 18:53 UTC
From: tom dot polak at post dot cz Assigned:
Status: Not a bug Package: Feature/Change Request
PHP Version: 4.2.3 OS: Windows, but all
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: tom dot polak at post dot cz
New email:
PHP Version: OS:

 

 [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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-02-24 13:28 UTC] michael dot mauch at gmx dot de
Have a look at
<http://www.php.net/manual/en/function.set-error-handler.php>, then
use an error handler like in the example:

// error handler function
function myErrorHandler ($errno, $errstr, $errfile, $errline) {
  print("Error {$msg} in file {$errfile} on line {$errline}\n");
}

where you get $errfile and $errline without problems. For your extra errors, you can use the trigger_error function.
 [2003-03-13 18:53 UTC] pollita@php.net
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 */
}
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 17:01:58 2024 UTC