Bug #79192 [Opn]: unset does not unset uninitialized typed properties completely
| From: | raincomplain at outlook dot com | Date: | Wed, 29 Jan 2020 17:32:36 +0000 |
| Subject: | Bug #79192 [Opn]: unset does not unset uninitialized typed properties completely | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-225226@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=79192&edit=1
ID: 79192
User updated by: raincomplain at outlook dot com
Reported by: raincomplain at outlook dot com
Summary: unset does not unset uninitialized typed properties
completely
Status: Open
Type: Bug
-Package: Testing related
+Package: Class/Object related
Operating System: Linux
PHP Version: 7.4.2
Block user comment: N
Private report: N
New Comment:
Changing bug package
Previous Comments:
------------------------------------------------------------------------
[2020-01-29 17:12:29] raincomplain at outlook dot com
Description:
------------
After unsetting an uninitialized typed property any attempt to modify that property will still
generate a fatal error an unset seems to set that property to null which is another issue. The later
can be illustrated after adding the magic method __get.
Test script:
---------------
**Without __get**
<?php
class Foo
{
public int $bar;
public function __set($prop, $val) {
throw new Exception('Dynamic properties are not allowed');
}
}
$f = new Foo();
unset($f->bar);
echo $f->bar
?>
**With __get**
class Foo
{
public int $bar;
public function __set($prop, $val) {
throw new Exception('Dynamic properties are not allowed');
}
public function __get($name)
{
echo 'works'.PHP_EOL;
}
}
$f = new Foo();
unset($f->bar);
echo $f->bar
Expected result:
----------------
The expected behavior is to emit a notice (PHP Notice: Undefined property: Foo::$bar) or prevent
unsetting uninitialized typed properties in the first place.
Actual result:
--------------
**Without __get**
Typed property Foo::$bar must not be accessed before initialization
**With __get**
works
PHP Fatal error: Uncaught TypeError: Typed property Foo::$bar must be int, null used
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=79192&edit=1