Bug #80705 [NEW]: If you unset a class property, the __get remembers the original type.
| From: | vali dot dr at gmail dot com | Date: | Wed, 03 Feb 2021 19:31:40 +0000 |
| Subject: | Bug #80705 [NEW]: If you unset a class property, the __get remembers the original type. | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-231934@lists.php.net to get a copy of this message | ||
From: vali dot dr at gmail dot com
Operating system: Linux
PHP version: 8.0.1
Package: Scripting Engine problem
Bug Type: Bug
Bug description:If you unset a class property, the __get remembers the original type.
Description:
------------
If you unset a property on a class, the __get magic method gets called
(good), but it's return must match the original, now unset, property
type. (bug?)
There should be a way to fully remove that property, either by
reflection or unset (including the return time)
Test script:
---------------
<?php declare(strict_types=1);
class Sample {
public int $foo = 123; # Start as in INT
public function __construct() {
unset($this->foo); # Remove the property
}
public function __get(string $name) { # Gets called, since
foo
dies not exist.
echo "__GET\n"; # Validate that it's called
return "string"; # Cannot return string since
foo was an int...
}
}
$test = new Sample();
echo $test->foo; # Throws error, since __get returns a string instead of
an int
Expected result:
----------------
__GET
string
Actual result:
--------------
__GET
PHP Fatal error: Uncaught TypeError: Cannot assign string to property
Sample::$foo of type int in ... .php:18
Stack trace:
#0 {main}
thrown in ...
--
Edit bug report at https://bugs.php.net/bug.php?id=80705&edit=1
--
Fix committed: https://bugs.php.net/fix.php?id=80705&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=80705&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=80705&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=80705&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=80705&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=80705&r=support
Expected behavior: https://bugs.php.net/fix.php?id=80705&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=80705&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=80705&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=80705&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=80705&r=phptooold
Daylight Savings: https://bugs.php.net/fix.php?id=80705&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=80705&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=80705&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=80705&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=80705&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=80705&r=mysqlcfg