php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #7473 @ not affecting error_handler
Submitted: 2000-10-25 23:57 UTC Modified: 2000-11-17 03:00 UTC
From: david@php.net Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 4.0.3pl1 OS: Linux
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: david@php.net
New email:
PHP Version: OS:

 

 [2000-10-25 23:57 UTC] david@php.net
It may be for a good reason that @ does not prevent the error_handler being called. However if this is true, then it should please be possible for the error_handler to determine whether the function call generating the error was prepended by @.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2000-11-01 02:33 UTC] andi@php.net
You should elaborate on what your concern is. I don't quite understand it. Do you have a reproducable bug script?
 [2000-11-01 02:49 UTC] david@php.net
If I call a function, and that function raises an error/warning, then error-control operator @ would usually prevent the "standard" PHP error handler from printing anything out. However if I am using a custom error handler, it does not prevent the handler being called.

An example/reproducing script with the "variable passed to reset() is not an array or object" error:

<?
$a = 1;

reset($a);  // A
@reset($a); // B

function custom_error_handler($errno, $errmsg, $errfile, $errline) {
  echo "Error handler: $errmsg at line $errline of $errfile\n";
}

set_error_handler('custom_error_handler');

reset($a);  // C
@reset($a); // D
?>

(A) triggers the standard error message as expected.
(B) "silences" the standard error message as expected.

(C) triggers the custom error handler as expected.
(D) triggers the custom error handler, ignoring the @.

(D) is my problem, as the @ is being ignored here, and the custom error handler is being called anyway.

Now it may be that you have a good reason for wanting the custom error handler to be called despite the error-control operator being used.

In that case I would suggest that you allow the custom error handler to detect whether the "@" prefix was used, perhaps with an addition optional parameter "bool $errorcontrol_prefix" being passed to the function. This would be true if the error in question would normally have been supressed because of the "@".

Thanks
 [2000-11-01 03:32 UTC] david@php.net
If I call a function, and that function raises an error/warning, then error-control operator @ would usually prevent the "standard" PHP error handler from printing anything out. However if I am using a custom error handler, it does not prevent the handler being called.

An example/reproducing script with the "variable passed to reset() is not an array or object" error:

<?
$a = 1;

reset($a);  // A
@reset($a); // B

function custom_error_handler($errno, $errmsg, $errfile, $errline) {
  echo "Error handler: $errmsg at line $errline of $errfile\n";
}

set_error_handler('custom_error_handler');

reset($a);  // C
@reset($a); // D
?>

(A) triggers the standard error message as expected.
(B) "silences" the standard error message as expected.

(C) triggers the custom error handler as expected.
(D) triggers the custom error handler, ignoring the @.

(D) is my problem, as the @ is being ignored here, and the custom error handler is being called anyway.

Now it may be that you have a good reason for wanting the custom error handler to be called despite the error-control operator being used.

In that case I would suggest that you allow the custom error handler to detect whether the "@" prefix was used, perhaps with an addition optional parameter "bool $errorcontrol_prefix" being passed to the function. This would be true if the error in question would normally have been supressed because of the "@".

Thanks
 [2000-11-05 11:37 UTC] stas@php.net
error_reporting() (without arguments) will return error reporting setting. It will return 0 if it's under @. Does it fit your needs?
 [2000-11-17 03:00 UTC] david@php.net
Thank you, I have updated the docs.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Nov 10 19:01:28 2024 UTC