php.net |  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 Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: yo at drmad dot org
New email:
PHP Version: OS:

 

 [2021-05-21 02:00 UTC] 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)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-05-23 04:46 UTC] krakjoe@php.net
-Status: Open +Status: Not a bug
 [2021-05-23 04:46 UTC] 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-23 08:05 UTC] nikic@php.net
This is also fixed in PHP 8.0, just not released yet.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 11:01:30 2024 UTC