Skip to content

Commit 1e50c81

Browse files
committed
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
2 parents 2d15845 + 8c6a7c3 commit 1e50c81

File tree

5 files changed

+88
-5
lines changed

5 files changed

+88
-5
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ PHP NEWS
55

66
- Core:
77
. Fixed bug #79244 (php crashes during parsing INI file). (Laruence)
8+
. Fixed bug #63206 (restore_error_handler does not restore previous errors
9+
mask). (Mark Plomer)
810

911
- COM:
1012
. Fixed bug #66322 (COMPersistHelper::SaveToFile can save to wrong location).

Zend/tests/bug63206.phpt

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
--TEST--
2+
Bug #63206 Fully support error_handler stacking, even inside the error_handler
3+
--FILE--
4+
<?php
5+
6+
set_error_handler(function() {
7+
echo 'First handler' . PHP_EOL;
8+
});
9+
10+
set_error_handler(function() {
11+
echo 'Second handler' . PHP_EOL;
12+
13+
set_error_handler(function() {
14+
echo 'Internal handler' . PHP_EOL;
15+
});
16+
17+
$triggerInternalNotice++; // warnings while handling the error should go into internal handler
18+
19+
restore_error_handler();
20+
});
21+
22+
$triggerNotice1++;
23+
$triggerNotice2++;
24+
?>
25+
--EXPECTF--
26+
Second handler
27+
Internal handler
28+
Second handler
29+
Internal handler

Zend/tests/bug63206_1.phpt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
--TEST--
2+
Bug #63206 Fully support error_handler stacking, even with null
3+
--FILE--
4+
<?php
5+
6+
set_error_handler(function() {
7+
echo 'First handler' . PHP_EOL;
8+
});
9+
10+
set_error_handler(function() {
11+
echo 'Second handler' . PHP_EOL;
12+
});
13+
14+
set_error_handler(null);
15+
16+
set_error_handler(function() {
17+
echo 'Fourth handler' . PHP_EOL;
18+
});
19+
20+
restore_error_handler();
21+
restore_error_handler();
22+
23+
$triggerNotice++;
24+
?>
25+
--EXPECTF--
26+
Second handler

Zend/tests/bug63206_2.phpt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
--TEST--
2+
Bug #63206 Fully support exception_handler stacking, even with null
3+
--FILE--
4+
<?php
5+
6+
set_exception_handler(function() {
7+
echo 'First handler' . PHP_EOL;
8+
});
9+
10+
set_exception_handler(function() {
11+
echo 'Second handler' . PHP_EOL;
12+
});
13+
14+
set_exception_handler(null);
15+
16+
set_exception_handler(function() {
17+
echo 'Fourth handler' . PHP_EOL;
18+
});
19+
20+
restore_exception_handler();
21+
restore_exception_handler();
22+
23+
throw new Exception();
24+
?>
25+
--EXPECTF--
26+
Second handler

Zend/zend_builtin_functions.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1645,11 +1645,11 @@ ZEND_FUNCTION(set_error_handler)
16451645

16461646
if (Z_TYPE(EG(user_error_handler)) != IS_UNDEF) {
16471647
ZVAL_COPY(return_value, &EG(user_error_handler));
1648-
1649-
zend_stack_push(&EG(user_error_handlers_error_reporting), &EG(user_error_handler_error_reporting));
1650-
zend_stack_push(&EG(user_error_handlers), &EG(user_error_handler));
16511648
}
16521649

1650+
zend_stack_push(&EG(user_error_handlers_error_reporting), &EG(user_error_handler_error_reporting));
1651+
zend_stack_push(&EG(user_error_handlers), &EG(user_error_handler));
1652+
16531653
if (Z_TYPE_P(error_handler) == IS_NULL) { /* unset user-defined handler */
16541654
ZVAL_UNDEF(&EG(user_error_handler));
16551655
return;
@@ -1712,10 +1712,10 @@ ZEND_FUNCTION(set_exception_handler)
17121712

17131713
if (Z_TYPE(EG(user_exception_handler)) != IS_UNDEF) {
17141714
ZVAL_COPY(return_value, &EG(user_exception_handler));
1715-
1716-
zend_stack_push(&EG(user_exception_handlers), &EG(user_exception_handler));
17171715
}
17181716

1717+
zend_stack_push(&EG(user_exception_handlers), &EG(user_exception_handler));
1718+
17191719
if (Z_TYPE_P(exception_handler) == IS_NULL) { /* unset user-defined handler */
17201720
ZVAL_UNDEF(&EG(user_exception_handler));
17211721
return;

0 commit comments

Comments
 (0)