Skip to content

Fix assertion failure in zend_std_read_property #16639

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions Zend/tests/gh16615_001.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
--TEST--
GH-16615 001 (Assertion failure in zend_std_read_property)
--FILE--
<?php

class Foo {
public string $bar {
set => $value;
}
}

$reflector = new ReflectionClass(Foo::class);

// Adds IS_PROP_LAZY to prop flags
$foo = $reflector->newLazyGhost(function ($ghost) {
$ghost->bar = 'bar';
});

echo $foo->bar;

?>
--EXPECT--
bar
24 changes: 24 additions & 0 deletions Zend/tests/gh16615_002.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
--TEST--
GH-16615 002 (Assertion failure in zend_std_read_property)
--FILE--
<?php

class Foo {
public string $bar {
set => $value;
}
public function __clone() {
try {
echo $this->bar;
} catch (Error $e) {
printf("%s: %s\n", $e::class, $e->getMessage());
}
}
}

// Adds IS_PROP_REINITABLE to prop flags
clone new Foo();

?>
--EXPECT--
Error: Typed property Foo::$bar must not be accessed before initialization
2 changes: 1 addition & 1 deletion Zend/zend_object_handlers.c
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,7 @@ ZEND_API zval *zend_std_read_property(zend_object *zobj, zend_string *name, int
if (UNEXPECTED(Z_TYPE_P(retval) == IS_UNDEF)) {
/* As hooked properties can't be unset, the only way to end up with an undef
* value is via an uninitialized property. */
ZEND_ASSERT(Z_PROP_FLAG_P(retval) == IS_PROP_UNINIT);
ZEND_ASSERT(Z_PROP_FLAG_P(retval) & IS_PROP_UNINIT);
goto uninit_error;
}

Expand Down