Bug #81064 [NEW]: __get() called accessing existing property which failed with TypeError before
| From: | yo at drmad dot org | Date: | Fri, 21 May 2021 02:00:32 +0000 |
| Subject: | Bug #81064 [NEW]: __get() called accessing existing property which failed with TypeError before | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-233941@lists.php.net to get a copy of this message | ||
From: yo at drmad dot org
Operating system: Manjaro
PHP version: 8.0.6
Package: Class/Object related
Bug Type: Bug
Bug description:__get() called accessing existing property which failed with TypeError before
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 bug report at https://bugs.php.net/bug.php?id=81064&edit=1
--
Fix committed: https://bugs.php.net/fix.php?id=81064&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=81064&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=81064&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=81064&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=81064&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=81064&r=support
Expected behavior: https://bugs.php.net/fix.php?id=81064&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=81064&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=81064&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=81064&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=81064&r=phptooold
Daylight Savings: https://bugs.php.net/fix.php?id=81064&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=81064&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=81064&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=81064&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=81064&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=81064&r=mysqlcfg