1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00

Merge branch 'PHP-8.4' into PHP-8.5

* PHP-8.4:
  Fix GH-20085: Assertion failure when combining lazy object get_properties exception with foreach loop
This commit is contained in:
Niels Dossche
2025-10-08 17:34:53 +02:00
3 changed files with 29 additions and 2 deletions

View File

@@ -0,0 +1,25 @@
--TEST--
GH-20085 (Assertion failure when combining lazy object get_properties exception with foreach loop)
--FILE--
<?php
class C {
public int $a;
public function __construct() {
$this->a = 1;
}
}
$obj = new C;
$reflector = new ReflectionClass(C::class);
foreach ($obj as &$value) {
$obj = $reflector->newLazyGhost(function ($obj) {
throw new Error;
});
}
echo !obj;
?>
--EXPECTF--
Fatal error: Uncaught Error in %s:%d
Stack trace:
#0 %s(%d): {closure:%s:%d}(Object(C))
#1 {main}
thrown in %s on line %d

View File

@@ -7307,7 +7307,7 @@ ZEND_VM_HANDLER(126, ZEND_FE_FETCH_RW, VAR, ANY, JMP_ADDR)
while (1) {
if (UNEXPECTED(pos >= fe_ht->nNumUsed)) {
/* reached end of iteration */
ZEND_VM_C_GOTO(fe_fetch_w_exit);
ZEND_VM_C_GOTO(fe_fetch_w_exit_exc);
}
pos++;
value = &p->val;
@@ -7403,6 +7403,7 @@ ZEND_VM_HANDLER(126, ZEND_FE_FETCH_RW, VAR, ANY, JMP_ADDR)
}
} else {
zend_error(E_WARNING, "foreach() argument must be of type array|object, %s given", zend_zval_value_name(array));
ZEND_VM_C_LABEL(fe_fetch_w_exit_exc):
if (UNEXPECTED(EG(exception))) {
UNDEF_RESULT();
HANDLE_EXCEPTION();

View File

@@ -23631,7 +23631,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_OPCODE_HANDLER_FUNC_CCONV ZEND_FE_FETCH_RW_S
while (1) {
if (UNEXPECTED(pos >= fe_ht->nNumUsed)) {
/* reached end of iteration */
goto fe_fetch_w_exit;
goto fe_fetch_w_exit_exc;
}
pos++;
value = &p->val;
@@ -23727,6 +23727,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_OPCODE_HANDLER_FUNC_CCONV ZEND_FE_FETCH_RW_S
}
} else {
zend_error(E_WARNING, "foreach() argument must be of type array|object, %s given", zend_zval_value_name(array));
fe_fetch_w_exit_exc:
if (UNEXPECTED(EG(exception))) {
UNDEF_RESULT();
HANDLE_EXCEPTION();