|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2001-08-08 13:23 UTC] joustin at plusnet dot pl
Seems that PHP cannot redirect 'Call to undefined function' errors to a custom error handler...
A sample (taken partly from the manual):
<pre>
<?php
// Define a simple error handler
function error_handler ($level, $message, $file, $line, $context) {
echo "An error of level $level was generated in file $file on line $line. \nThe error message was: $message \nThe following variables were set in the scope that the error occurred in: <blockquote> ";
print_r ($context);
print "\n</blockquote>";
}
// Set the error handler to the error_handler() function
set_error_handler ('error_handler');
trigger_error ("Some other error");
whatever(); // <- this will crash make the script die without calling the custom error_handler
?>
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Nov 05 10:00:02 2025 UTC |
The assertion "... Seems that PHP cannot redirect 'Call to undefined function' errors to a custom error handler..." is incorrect. This seems to be a problem w/ the person reporting the bug *not* using the error_reporting() function, as it is clearly noted in the manual example, changing the code to read: <?php define (ERROR,E_USER_WARNING); define (WARNING,E_USER_NOTICE); // set the error reporting level for this script error_reporting (FATAL | ERROR | WARNING); // Define a simple error handler function error_handler ($level, $message, $file, $line, $context) { echo "An error of level $level was generated in file $file on line $line. \nThe error message was: $message \nThe following variables were set in the scope that the error occurred in: <blockquote> "; print_r ($context); print "\n</blockquote>"; } // Set the error handler to the error_handler() function set_error_handler ('error_handler'); trigger_error ("Some other error"); whatever(); ?> The output is: An error of level 1024 was generated in file bugtest.php on line 20. The error message was: Some other error The following variables were set in the scope that the error occurred in: <blockquote> Array ( [PWD] => /tmp [... snip ...] [_] => /usr/local/bin/php [PHP_SELF] => [argv] => Array ( [0] => bugtest.php ) [argc] => 1 [HTTP_POST_VARS] => Array ( ) [HTTP_GET_VARS] => Array [...snip...] </blockquote> This was tested with 4.0.6 on RH 7.1, more information is requested from the person reporting the bug, before it is reclassified as bogus.Using: error_reporting("E_ERROR"); does not work (same result as E_ALL), even though in Zend/zend_execute.c that is the error level raised. In Zend/zend.c the zend_error() function hands the error to zend_error_cb, which points to one of the utility functions created during zend_startup() (called in main/main.c) I cannot track the chain down more, my C is very rusty.