|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2020-03-12 17:12 UTC] beberlei@php.net
-Status: Open
+Status: Not a bug
[2020-03-12 17:12 UTC] beberlei@php.net
[2020-04-13 14:47 UTC] ocramius@php.net
[2020-04-13 15:08 UTC] requinix@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 14:00:01 2025 UTC |
Description: ------------ A uninitialized typed property cannot accessed in __get method until unset() it. Test on 7.4.0~7.4.3, 7.4.0 is works. Test script: --------------- <?php class Foo { public int $bar; public function __get($name) { if ('bar' === $name) { return $this->bar = 1; } } } $foo1 = new Foo(); var_dump($foo1); var_dump($foo1->bar); $foo2 = new Foo(); var_dump($foo2); unset($foo2->bar); var_dump($foo2); var_dump($foo2->bar); Expected result: ---------------- object(Foo)#1 (0) { ["bar"]=> uninitialized(int) } int(1) object(Foo)#2 (0) { ["bar"]=> uninitialized(int) } object(Foo)#2 (0) { ["bar"]=> uninitialized(int) } int(1) Actual result: -------------- object(Foo)#1 (0) { ["bar"]=> uninitialized(int) } Warning: Uncaught Error: Typed property Foo::$bar must not be accessed before initialization in php shell code:1 Stack trace: #0 {main} thrown in php shell code on line 1 object(Foo)#2 (0) { ["bar"]=> uninitialized(int) } object(Foo)#2 (0) { ["bar"]=> uninitialized(int) } int(1)