Bug #81064 [Nab]: __get() called accessing existing property which failed with TypeError before

From: Date: Sun, 23 May 2021 08:05:00 +0000
Subject: Bug #81064 [Nab]: __get() called accessing existing property which failed with TypeError before
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-233993@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=81064&edit=1 ID: 81064 Updated by: nikic@php.net Reported by: yo at drmad dot org Summary: __get() called accessing existing property which failed with TypeError before Status: Not a bug Type: Bug Package: Class/Object related Operating System: Manjaro PHP Version: 8.0.6 Block user comment: N Private report: N New Comment: This is also fixed in PHP 8.0, just not released yet. Previous Comments: ------------------------------------------------------------------------ [2021-05-23 04:46:04] krakjoe@php.net Thank you for taking the time to report a problem with PHP. Unfortunately you are not using a current version of PHP -- the problem might already be fixed. Please download a new PHP version from http://www.php.net/downloads.php If you are able to reproduce the bug with one of the latest versions of PHP, please change the PHP version on this bug report to the version you tested and change the status back to "Open". Again, thank you for your continued support of PHP. This has been fixed in 8.1 ------------------------------------------------------------------------ [2021-05-21 02:00:32] yo at drmad dot org 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) ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=81064&edit=1

« previous php.bugs (#233993) next »