Skip to content

Commit bfedb4e

Browse files
committed
Merge branch 'PHP-8.1'
* PHP-8.1: Fix non-reentirant startiong or error recording from error handler
2 parents ddb04d4 + c6a53f9 commit bfedb4e

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

Zend/tests/record_errors_001.phpt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
--TEST--
2+
Error recording in error handler
3+
--FILE--
4+
<?php
5+
set_error_handler(function($code, $msg) {
6+
echo "Error: $msg\n";
7+
new class extends DateTime {
8+
};
9+
});
10+
new class extends DateTime {
11+
function getTimezone() {}
12+
};
13+
?>
14+
--EXPECT--
15+
Error: Return type of DateTime@anonymous::getTimezone() should either be compatible with DateTime::getTimezone(): DateTimeZone|false, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice

Zend/zend.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1326,6 +1326,10 @@ ZEND_API ZEND_COLD void zend_error_zstr_at(
13261326
zend_stack loop_var_stack;
13271327
zend_stack delayed_oplines_stack;
13281328
int type = orig_type & E_ALL;
1329+
bool orig_record_errors;
1330+
uint32_t orig_num_errors;
1331+
zend_error_info **orig_errors;
1332+
zend_result res;
13291333

13301334
/* If we're executing a function during SCCP, count any warnings that may be emitted,
13311335
* but don't perform any other error handling. */
@@ -1419,7 +1423,20 @@ ZEND_API ZEND_COLD void zend_error_zstr_at(
14191423
CG(in_compilation) = 0;
14201424
}
14211425

1422-
if (call_user_function(CG(function_table), NULL, &orig_user_error_handler, &retval, 4, params) == SUCCESS) {
1426+
orig_record_errors = EG(record_errors);
1427+
orig_num_errors = EG(num_errors);
1428+
orig_errors = EG(errors);
1429+
EG(record_errors) = false;
1430+
EG(num_errors) = 0;
1431+
EG(errors) = NULL;
1432+
1433+
res = call_user_function(CG(function_table), NULL, &orig_user_error_handler, &retval, 4, params);
1434+
1435+
EG(record_errors) = orig_record_errors;
1436+
EG(num_errors) = orig_num_errors;
1437+
EG(errors) = orig_errors;
1438+
1439+
if (res == SUCCESS) {
14231440
if (Z_TYPE(retval) != IS_UNDEF) {
14241441
if (Z_TYPE(retval) == IS_FALSE) {
14251442
zend_error_cb(orig_type, error_filename, error_lineno, message);

0 commit comments

Comments
 (0)