Skip to content

Commit e9a6f0f

Browse files
committed
MFH: User error handlers no longer catch supressed errors
1 parent fd0d44f commit e9a6f0f

4 files changed

Lines changed: 40 additions & 22 deletions

File tree

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
--TEST--
2+
user defined error handler + set_error_handling(EH_THROW)
3+
--SKIPIF--
4+
<?php if (!extension_loaded("spl") || is_dir('/this/path/does/not/exist')) die("skip"); ?>
5+
--FILE--
6+
<?php
7+
$dir = '/this/path/does/not/exist';
8+
9+
set_error_handler('my_error_handler');
10+
function my_error_handler() {$a = func_get_args(); print "in error handler\n"; }
11+
12+
try {
13+
print "before\n";
14+
$iter = new DirectoryIterator($dir);
15+
print get_class($iter) . "\n";
16+
print "after\n";
17+
} catch (Exception $e) {
18+
print "in catch: ".$e->getMessage()."\n";
19+
}
20+
?>
21+
==DONE==
22+
<?php exit(0); ?>
23+
--EXPECT--
24+
before
25+
in catch: DirectoryIterator::__construct(/this/path/does/not/exist): failed to open dir: No such file or directory
26+
==DONE==

main/main.c

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -778,17 +778,15 @@ PHPAPI void php_html_puts(const char *str, uint size TSRMLS_DC)
778778
/* {{{ php_suppress_errors */
779779
PHPAPI void php_set_error_handling(error_handling_t error_handling, zend_class_entry *exception_class TSRMLS_DC)
780780
{
781-
PG(error_handling) = error_handling;
782-
PG(exception_class) = exception_class;
783-
if (PG(last_error_message)) {
784-
free(PG(last_error_message));
785-
PG(last_error_message) = NULL;
786-
}
787-
if (PG(last_error_file)) {
788-
free(PG(last_error_file));
789-
PG(last_error_file) = NULL;
781+
EG(error_handling) = error_handling;
782+
EG(exception_class) = exception_class;
783+
784+
if (error_handling == EH_NORMAL) {
785+
EG(user_error_handler) = EG(user_error_handler_old);
786+
} else {
787+
EG(user_error_handler_old) = EG(user_error_handler);
788+
EG(user_error_handler) = NULL;
790789
}
791-
PG(last_error_lineno) = 0;
792790
}
793791
/* }}} */
794792

@@ -833,7 +831,7 @@ static void php_error_cb(int type, const char *error_filename, const uint error_
833831
}
834832

835833
/* according to error handling mode, suppress error, throw exception or show it */
836-
if (PG(error_handling) != EH_NORMAL) {
834+
if (EG(error_handling) != EH_NORMAL) {
837835
switch (type) {
838836
case E_ERROR:
839837
case E_CORE_ERROR:
@@ -854,8 +852,8 @@ static void php_error_cb(int type, const char *error_filename, const uint error_
854852
/* throw an exception if we are in EH_THROW mode
855853
* but DO NOT overwrite a pending exception
856854
*/
857-
if (PG(error_handling) == EH_THROW && !EG(exception)) {
858-
zend_throw_error_exception(PG(exception_class), buffer, 0, type TSRMLS_CC);
855+
if (EG(error_handling) == EH_THROW && !EG(exception)) {
856+
zend_throw_error_exception(EG(exception_class), buffer, 0, type TSRMLS_CC);
859857
}
860858
efree(buffer);
861859
return;
@@ -1729,7 +1727,8 @@ int php_module_startup(sapi_module_struct *sf, zend_module_entry *additional_mod
17291727
PG(last_error_message) = NULL;
17301728
PG(last_error_file) = NULL;
17311729
PG(last_error_lineno) = 0;
1732-
PG(error_handling) = EH_NORMAL;
1730+
EG(error_handling) = EH_NORMAL;
1731+
EG(exception_class) = NULL;
17331732
PG(disable_functions) = NULL;
17341733
PG(disable_classes) = NULL;
17351734

main/php.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -278,12 +278,7 @@ int cfgparse(void);
278278
END_EXTERN_C()
279279

280280
#define php_error zend_error
281-
282-
typedef enum {
283-
EH_NORMAL = 0,
284-
EH_SUPPRESS,
285-
EH_THROW
286-
} error_handling_t;
281+
#define error_handling_t zend_error_handling_t
287282

288283
BEGIN_EXTERN_C()
289284
PHPAPI void php_set_error_handling(error_handling_t error_handling, zend_class_entry *exception_class TSRMLS_DC);

main/php_globals.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,6 @@ struct _php_core_globals {
150150
char *last_error_message;
151151
char *last_error_file;
152152
int last_error_lineno;
153-
error_handling_t error_handling;
154-
zend_class_entry *exception_class;
155153

156154
char *disable_functions;
157155
char *disable_classes;

0 commit comments

Comments
 (0)