Skip to content

Commit 9343cd4

Browse files
committed
Fix assertion failure in zend_std_read_property
1 parent 396b995 commit 9343cd4

File tree

3 files changed

+48
-1
lines changed

3 files changed

+48
-1
lines changed

Zend/tests/gh16615_001.phpt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
--TEST--
2+
GH-16615 001 (Assertion failure in zend_std_read_property)
3+
--FILE--
4+
<?php
5+
6+
class Foo {
7+
public string $bar {
8+
set => $value;
9+
}
10+
}
11+
12+
$reflector = new ReflectionClass(Foo::class);
13+
14+
// Adds IS_PROP_LAZY to prop flags
15+
$foo = $reflector->newLazyGhost(function ($ghost) {
16+
$ghost->bar = 'bar';
17+
});
18+
19+
echo $foo->bar;
20+
21+
?>
22+
--EXPECT--
23+
bar

Zend/tests/gh16615_002.phpt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
--TEST--
2+
GH-16615 002 (Assertion failure in zend_std_read_property)
3+
--FILE--
4+
<?php
5+
6+
class Foo {
7+
public string $bar {
8+
set => $value;
9+
}
10+
public function __clone() {
11+
echo $this->bar;
12+
}
13+
}
14+
15+
// Adds IS_PROP_REINITABLE to prop flags
16+
clone new Foo();
17+
18+
?>
19+
--EXPECTF--
20+
Fatal error: Uncaught Error: Typed property Foo::$bar must not be accessed before initialization in %s:%d
21+
Stack trace:
22+
#0 %s(%d): Foo->__clone()
23+
#1 {main}
24+
thrown in %s on line %d

Zend/zend_object_handlers.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -791,7 +791,7 @@ ZEND_API zval *zend_std_read_property(zend_object *zobj, zend_string *name, int
791791
if (UNEXPECTED(Z_TYPE_P(retval) == IS_UNDEF)) {
792792
/* As hooked properties can't be unset, the only way to end up with an undef
793793
* value is via an uninitialized property. */
794-
ZEND_ASSERT(Z_PROP_FLAG_P(retval) == IS_PROP_UNINIT);
794+
ZEND_ASSERT(Z_PROP_FLAG_P(retval) & IS_PROP_UNINIT);
795795
goto uninit_error;
796796
}
797797

0 commit comments

Comments
 (0)