- Core:
. Fixed bug #79979 (passing value to by-ref param via CUFA crashes). (cmb,
Nikita)
+ . Fixed bug #80037 (Typed property must not be accessed before initialization
+ when __get() declared). (Nikita)
- Calendar:
. Fixed bug #80007 (Potential type confusion in unixtojd() parameter parsing).
--- /dev/null
+--TEST--
+Bug #80037: Typed property must not be accessed before initialization when __get() declared
+--FILE--
+<?php
+
+final class A
+{
+ public string $a;
+
+ public static function fromArray(array $props): self
+ {
+ $me = new static;
+ foreach ($props as $k => &$v) {
+ $me->{$k} = &$v; # try to remove &
+ }
+ return $me;
+ }
+
+ public function __get($name)
+ {
+ throw new \LogicException("Property '$name' is not defined.");
+ }
+}
+
+var_dump(A::fromArray(['a' => 'foo']));
+
+?>
+--EXPECT--
+object(A)#1 (1) {
+ ["a"]=>
+ string(3) "foo"
+}
+++ /dev/null
---TEST--
-Bug #80039: Illegal string offset and Cannot create references to/from string offsets
---FILE--
-<?php
-
-final class A
-{
- public string $a;
-
- public static function fromArray(array $props): self
- {
- $me = new static;
- foreach ($props as $k => &$v) {
- $me->{$k} = &$v;
- }
- return $me;
- }
-
- public function __get($name)
- {
- throw new \LogicException("Property '$name' is not defined.");
- }
-}
-
-class ObjectHelpers
-{
- public static function hasProperty(string $class, string $name)
- {
- static $cache = [];
- $prop = &$cache[$class][$name]; # <-- emits error
- var_dump($prop);
- }
-}
-
-set_exception_handler(function ($e) {
- ObjectHelpers::hasProperty(A::class, 'a');
-});
-
-A::fromArray(['a' => 'foo']);
-
-?>
---EXPECT--
-NULL
retval = OBJ_PROP(zobj, property_offset);
if (UNEXPECTED(Z_TYPE_P(retval) == IS_UNDEF)) {
if (EXPECTED(!zobj->ce->__get) ||
- UNEXPECTED((*zend_get_property_guard(zobj, name)) & IN_GET)) {
+ UNEXPECTED((*zend_get_property_guard(zobj, name)) & IN_GET) ||
+ UNEXPECTED(prop_info && Z_PROP_FLAG_P(retval) == IS_PROP_UNINIT)) {
if (UNEXPECTED(type == BP_VAR_RW || type == BP_VAR_R)) {
if (UNEXPECTED(prop_info)) {
zend_throw_error(NULL,