summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikita Popov <nikita.ppv@gmail.com>2020-02-25 12:44:01 +0100
committerNikita Popov <nikita.ppv@gmail.com>2020-02-25 12:44:11 +0100
commit1e50c81f6fbb1ff6dd40fc5f02919a3351978254 (patch)
treeab8a2f627762b60e98ca8afa4e87006498174f0b
parent2d15845ae11cfcbf14debcb1f7b480499de66185 (diff)
parent8c6a7c3326f000af0a8ea266143059e5a463e626 (diff)
downloadphp-git-1e50c81f6fbb1ff6dd40fc5f02919a3351978254.tar.gz
Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3: Fix #63206: Fully support error/exception_handler stacking, even with null or inside the handler
-rw-r--r--NEWS2
-rw-r--r--Zend/tests/bug63206.phpt29
-rw-r--r--Zend/tests/bug63206_1.phpt26
-rw-r--r--Zend/tests/bug63206_2.phpt26
-rw-r--r--Zend/zend_builtin_functions.c10
5 files changed, 88 insertions, 5 deletions
diff --git a/NEWS b/NEWS
index 7383cd6a94..c70eaa7bb3 100644
--- a/NEWS
+++ b/NEWS
@@ -5,6 +5,8 @@ PHP NEWS
- Core:
. Fixed bug #79244 (php crashes during parsing INI file). (Laruence)
+ . Fixed bug #63206 (restore_error_handler does not restore previous errors
+ mask). (Mark Plomer)
- COM:
. Fixed bug #66322 (COMPersistHelper::SaveToFile can save to wrong location).
diff --git a/Zend/tests/bug63206.phpt b/Zend/tests/bug63206.phpt
new file mode 100644
index 0000000000..dc7bb1fd1d
--- /dev/null
+++ b/Zend/tests/bug63206.phpt
@@ -0,0 +1,29 @@
+--TEST--
+Bug #63206 Fully support error_handler stacking, even inside the error_handler
+--FILE--
+<?php
+
+set_error_handler(function() {
+ echo 'First handler' . PHP_EOL;
+});
+
+set_error_handler(function() {
+ echo 'Second handler' . PHP_EOL;
+
+ set_error_handler(function() {
+ echo 'Internal handler' . PHP_EOL;
+ });
+
+ $triggerInternalNotice++; // warnings while handling the error should go into internal handler
+
+ restore_error_handler();
+});
+
+$triggerNotice1++;
+$triggerNotice2++;
+?>
+--EXPECTF--
+Second handler
+Internal handler
+Second handler
+Internal handler
diff --git a/Zend/tests/bug63206_1.phpt b/Zend/tests/bug63206_1.phpt
new file mode 100644
index 0000000000..f08f913824
--- /dev/null
+++ b/Zend/tests/bug63206_1.phpt
@@ -0,0 +1,26 @@
+--TEST--
+Bug #63206 Fully support error_handler stacking, even with null
+--FILE--
+<?php
+
+set_error_handler(function() {
+ echo 'First handler' . PHP_EOL;
+});
+
+set_error_handler(function() {
+ echo 'Second handler' . PHP_EOL;
+});
+
+set_error_handler(null);
+
+set_error_handler(function() {
+ echo 'Fourth handler' . PHP_EOL;
+});
+
+restore_error_handler();
+restore_error_handler();
+
+$triggerNotice++;
+?>
+--EXPECTF--
+Second handler
diff --git a/Zend/tests/bug63206_2.phpt b/Zend/tests/bug63206_2.phpt
new file mode 100644
index 0000000000..7a2bf38543
--- /dev/null
+++ b/Zend/tests/bug63206_2.phpt
@@ -0,0 +1,26 @@
+--TEST--
+Bug #63206 Fully support exception_handler stacking, even with null
+--FILE--
+<?php
+
+set_exception_handler(function() {
+ echo 'First handler' . PHP_EOL;
+});
+
+set_exception_handler(function() {
+ echo 'Second handler' . PHP_EOL;
+});
+
+set_exception_handler(null);
+
+set_exception_handler(function() {
+ echo 'Fourth handler' . PHP_EOL;
+});
+
+restore_exception_handler();
+restore_exception_handler();
+
+throw new Exception();
+?>
+--EXPECTF--
+Second handler
diff --git a/Zend/zend_builtin_functions.c b/Zend/zend_builtin_functions.c
index 266b50599b..5658ec1158 100644
--- a/Zend/zend_builtin_functions.c
+++ b/Zend/zend_builtin_functions.c
@@ -1645,11 +1645,11 @@ ZEND_FUNCTION(set_error_handler)
if (Z_TYPE(EG(user_error_handler)) != IS_UNDEF) {
ZVAL_COPY(return_value, &EG(user_error_handler));
-
- zend_stack_push(&EG(user_error_handlers_error_reporting), &EG(user_error_handler_error_reporting));
- zend_stack_push(&EG(user_error_handlers), &EG(user_error_handler));
}
+ zend_stack_push(&EG(user_error_handlers_error_reporting), &EG(user_error_handler_error_reporting));
+ zend_stack_push(&EG(user_error_handlers), &EG(user_error_handler));
+
if (Z_TYPE_P(error_handler) == IS_NULL) { /* unset user-defined handler */
ZVAL_UNDEF(&EG(user_error_handler));
return;
@@ -1712,10 +1712,10 @@ ZEND_FUNCTION(set_exception_handler)
if (Z_TYPE(EG(user_exception_handler)) != IS_UNDEF) {
ZVAL_COPY(return_value, &EG(user_exception_handler));
-
- zend_stack_push(&EG(user_exception_handlers), &EG(user_exception_handler));
}
+ zend_stack_push(&EG(user_exception_handlers), &EG(user_exception_handler));
+
if (Z_TYPE_P(exception_handler) == IS_NULL) { /* unset user-defined handler */
ZVAL_UNDEF(&EG(user_exception_handler));
return;