mirror of
https://github.com/php/php-src.git
synced 2025-01-22 19:54:13 +08:00
MFH: User error handlers no longer catch supressed errors
This commit is contained in:
parent
fd0d44f0a7
commit
e9a6f0f24a
26
ext/standard/tests/general_functions/bug44295.phpt
Normal file
26
ext/standard/tests/general_functions/bug44295.phpt
Normal file
@ -0,0 +1,26 @@
|
||||
--TEST--
|
||||
user defined error handler + set_error_handling(EH_THROW)
|
||||
--SKIPIF--
|
||||
<?php if (!extension_loaded("spl") || is_dir('/this/path/does/not/exist')) die("skip"); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
$dir = '/this/path/does/not/exist';
|
||||
|
||||
set_error_handler('my_error_handler');
|
||||
function my_error_handler() {$a = func_get_args(); print "in error handler\n"; }
|
||||
|
||||
try {
|
||||
print "before\n";
|
||||
$iter = new DirectoryIterator($dir);
|
||||
print get_class($iter) . "\n";
|
||||
print "after\n";
|
||||
} catch (Exception $e) {
|
||||
print "in catch: ".$e->getMessage()."\n";
|
||||
}
|
||||
?>
|
||||
==DONE==
|
||||
<?php exit(0); ?>
|
||||
--EXPECT--
|
||||
before
|
||||
in catch: DirectoryIterator::__construct(/this/path/does/not/exist): failed to open dir: No such file or directory
|
||||
==DONE==
|
27
main/main.c
27
main/main.c
@ -778,17 +778,15 @@ PHPAPI void php_html_puts(const char *str, uint size TSRMLS_DC)
|
||||
/* {{{ php_suppress_errors */
|
||||
PHPAPI void php_set_error_handling(error_handling_t error_handling, zend_class_entry *exception_class TSRMLS_DC)
|
||||
{
|
||||
PG(error_handling) = error_handling;
|
||||
PG(exception_class) = exception_class;
|
||||
if (PG(last_error_message)) {
|
||||
free(PG(last_error_message));
|
||||
PG(last_error_message) = NULL;
|
||||
EG(error_handling) = error_handling;
|
||||
EG(exception_class) = exception_class;
|
||||
|
||||
if (error_handling == EH_NORMAL) {
|
||||
EG(user_error_handler) = EG(user_error_handler_old);
|
||||
} else {
|
||||
EG(user_error_handler_old) = EG(user_error_handler);
|
||||
EG(user_error_handler) = NULL;
|
||||
}
|
||||
if (PG(last_error_file)) {
|
||||
free(PG(last_error_file));
|
||||
PG(last_error_file) = NULL;
|
||||
}
|
||||
PG(last_error_lineno) = 0;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
@ -833,7 +831,7 @@ static void php_error_cb(int type, const char *error_filename, const uint error_
|
||||
}
|
||||
|
||||
/* according to error handling mode, suppress error, throw exception or show it */
|
||||
if (PG(error_handling) != EH_NORMAL) {
|
||||
if (EG(error_handling) != EH_NORMAL) {
|
||||
switch (type) {
|
||||
case E_ERROR:
|
||||
case E_CORE_ERROR:
|
||||
@ -854,8 +852,8 @@ static void php_error_cb(int type, const char *error_filename, const uint error_
|
||||
/* throw an exception if we are in EH_THROW mode
|
||||
* but DO NOT overwrite a pending exception
|
||||
*/
|
||||
if (PG(error_handling) == EH_THROW && !EG(exception)) {
|
||||
zend_throw_error_exception(PG(exception_class), buffer, 0, type TSRMLS_CC);
|
||||
if (EG(error_handling) == EH_THROW && !EG(exception)) {
|
||||
zend_throw_error_exception(EG(exception_class), buffer, 0, type TSRMLS_CC);
|
||||
}
|
||||
efree(buffer);
|
||||
return;
|
||||
@ -1729,7 +1727,8 @@ int php_module_startup(sapi_module_struct *sf, zend_module_entry *additional_mod
|
||||
PG(last_error_message) = NULL;
|
||||
PG(last_error_file) = NULL;
|
||||
PG(last_error_lineno) = 0;
|
||||
PG(error_handling) = EH_NORMAL;
|
||||
EG(error_handling) = EH_NORMAL;
|
||||
EG(exception_class) = NULL;
|
||||
PG(disable_functions) = NULL;
|
||||
PG(disable_classes) = NULL;
|
||||
|
||||
|
@ -278,12 +278,7 @@ int cfgparse(void);
|
||||
END_EXTERN_C()
|
||||
|
||||
#define php_error zend_error
|
||||
|
||||
typedef enum {
|
||||
EH_NORMAL = 0,
|
||||
EH_SUPPRESS,
|
||||
EH_THROW
|
||||
} error_handling_t;
|
||||
#define error_handling_t zend_error_handling_t
|
||||
|
||||
BEGIN_EXTERN_C()
|
||||
PHPAPI void php_set_error_handling(error_handling_t error_handling, zend_class_entry *exception_class TSRMLS_DC);
|
||||
|
@ -150,8 +150,6 @@ struct _php_core_globals {
|
||||
char *last_error_message;
|
||||
char *last_error_file;
|
||||
int last_error_lineno;
|
||||
error_handling_t error_handling;
|
||||
zend_class_entry *exception_class;
|
||||
|
||||
char *disable_functions;
|
||||
char *disable_classes;
|
||||
|
Loading…
Reference in New Issue
Block a user