From: raincomplain at outlook dot com Operating system: Linux PHP version: 7.4.2 Package: Testing related Bug Type: Bug Bug description:unset does not unset uninitialized typed properties completely
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 bug report at https://bugs.php.net/bug.php?id=79192&edit=1 -- Fix committed: https://bugs.php.net/fix.php?id=79192&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=79192&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=79192&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=79192&r=needscript Try newer version: https://bugs.php.net/fix.php?id=79192&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=79192&r=support Expected behavior: https://bugs.php.net/fix.php?id=79192&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=79192&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=79192&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=79192&r=globals PHP version support discontinued: https://bugs.php.net/fix.php?id=79192&r=phptooold Daylight Savings: https://bugs.php.net/fix.php?id=79192&r=dst IIS Stability: https://bugs.php.net/fix.php?id=79192&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=79192&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=79192&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=79192&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=79192&r=mysqlcfg