|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2020-01-29 17:32 UTC] raincomplain at outlook dot com
-Package: Testing related
+Package: Class/Object related
[2020-01-29 17:32 UTC] raincomplain at outlook dot com
[2020-01-30 09:05 UTC] raincomplain at outlook dot com
[2020-01-30 09:15 UTC] nikic@php.net
-Status: Open
+Status: Not a bug
[2020-01-30 09:15 UTC] nikic@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Nov 02 01:00:02 2025 UTC |
Description: ------------ After unsetting an uninitialized typed property any attempt to modify that property will still generate a fatal error an unset seems to set that property to null which is another issue. The later can be illustrated after adding the magic method __get. Test script: --------------- **Without __get** <?php class Foo { public int $bar; public function __set($prop, $val) { throw new Exception('Dynamic properties are not allowed'); } } $f = new Foo(); unset($f->bar); echo $f->bar ?> **With __get** class Foo { public int $bar; public function __set($prop, $val) { throw new Exception('Dynamic properties are not allowed'); } public function __get($name) { echo 'works'.PHP_EOL; } } $f = new Foo(); unset($f->bar); echo $f->bar Expected result: ---------------- The expected behavior is to emit a notice (PHP Notice: Undefined property: Foo::$bar) or prevent unsetting uninitialized typed properties in the first place. Actual result: -------------- **Without __get** Typed property Foo::$bar must not be accessed before initialization **With __get** works PHP Fatal error: Uncaught TypeError: Typed property Foo::$bar must be int, null used