|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[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 @. PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Nov 02 06:00:01 2025 UTC |
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 "@". ThanksIf 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