|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2021-05-23 04:46 UTC] krakjoe@php.net
-Status: Open
+Status: Not a bug
[2021-05-23 04:46 UTC] krakjoe@php.net
[2021-05-23 08:05 UTC] nikic@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 15 21:00:01 2025 UTC |
Description: ------------ Catching a TypeError while assigning a wrong type value to a typed property makes that property 'disappear', calling __get() magic method if accessed afterwards, and failing with a assigning error, even if there is no assigning. Tested on PHP 7.4.18 and PHP 8.0.6 Test script: --------------- <?php class test { public int $a; public function __get($p) { echo "$p doesn't exist?\n"; } } $t = new test; try { $t->a = "Wrong type"; } catch (TypeError $e) {} echo $t->a; Expected result: ---------------- PHP Fatal error: Uncaught Error: Typed property test::$a must not be accessed before initialization in /tmp/test.php:15 Actual result: -------------- a doesn't exist? Fatal error: Uncaught TypeError: Typed property test::$a must be int, null used in /tmp/test.php:15 ("Cannot assign null to property test::$a of type int" in PHP 8)