|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #81064 __get() called accessing existing property which failed with TypeError before
Submitted: 2021-05-21 02:00 UTC Modified: 2021-05-23 08:05 UTC
From: yo at drmad dot org Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 8.0.6 OS: Manjaro
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: yo at drmad dot org
New email:
PHP Version: OS:


 [2021-05-21 02:00 UTC] yo at drmad dot org
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:
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)


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2021-05-23 04:46 UTC]
-Status: Open +Status: Not a bug
 [2021-05-23 04:46 UTC]
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

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-23 08:05 UTC]
This is also fixed in PHP 8.0, just not released yet.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu May 23 18:01:35 2024 UTC