mirror of
https://github.com/php/php-src.git
synced 2026-03-24 00:02:20 +01:00
In this test, we will loop once, and then replace the object with an instance that'll throw on property construction in Z_OBJPROP_P() in the ZEND_FE_FETCH_RW VM handler. Since at that point `pos >= fe_ht->nNumUsed`, we exit via `fe_fetch_w_exit` without checking for an exception, causing incorrect continuation of the code and an eventual assertion failure. To solve this, we perform an exception check at the end of the iteration. This should be sufficient to guarantee the exception is checked in time as failure of get_properties() via Z_OBJPROP_P() will always result in an empty hash table. This should also be more efficient than the alternative fix that checks for an exception right after Z_OBJPROP_P() as that would be executed at each iteration. Closes GH-20098.
26 lines
543 B
PHP
26 lines
543 B
PHP
--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
|