Bug #78809 [Opn->Spm]: Uninitialized typed properties
[email protected] Wed, 13 Nov 2019 19:40:59 +0000
| Newsgroups | php.standards |
|---|---|
| Message-ID | <[email protected]> |
Edit report at https://bugs.php.net/bug.php?id=78809&edit=1 ID: 78809 Updated by: [email protected] Reported by: krmgns at gmail dot com Summary: Uninitialized typed properties -Status: Open +Status: Spam Type: Bug Package: PHP Language Specification Operating System: Ubuntu 18.04 PHP Version: 7.4.0RC5 Block user comment: N Private report: N Previous Comments: ------------------------------------------------------------------------ [2019-11-13 19:18:41] henry dot paradiz at gmail dot com Yikes ------------------------------------------------------------------------ [2019-11-13 19:16:46] krmgns at gmail dot com Description: ------------ While throwing when try to access to any uninitialized typed property (eg: $o->x == null), the codes below are just causing notice. BTW, error message is so weird. We were expecting something like this; "Do not touch that f**king TYPED PROPERTY, it's a f**king TYPED PROPERTY and you poor should know your place while coding with highness PHP! Respect and behave yourself!" AND, while some other main stream languages allowing to access them (to uninitialized properties) simply saying null (or nil), why PHP is forcing us to use empty(), isset() or ?? operator? Does PHP want a to be cruel language or enjoying to usage of empty() and other likely-stuff above, denying us to do checks with null ($o->x == null)? Also it is not just a null check issue, but to access in any other way (eg: $o->x < 0, !($o->x ^ 0) etc). All aside, I am not angry or hating PHP, but simply was expecting more easiness, productivity and better development experience while coding with PHP all after 15 years my own PHP experience... Dropping here some links hoping you to check them; https://twitter.com/krmgns/status/1194293566899675136 https://twitter.com/nikita_ppv/status/1194301509036658691 (nikic' comment) https://gist.github.com/k-gun/43ea9ea0e53d690fe4e23005a98e5cfa Some other languages behavior for uninitialized properties. https://gist.github.com/k-gun/514e8ad8cd9b95eadf8910ab10f4e373 Test script: --------------- $a = new class { var int $i; }; var_dump($a->i == null); var_dump($a->i++); $a = new class { var string $s; }; var_dump($a->s == null); var_dump($a->s .= ""); Expected result: ---------------- Fatal error: Uncaught Error: Typed property class@anonymous::$i must not be accessed before initialization in /var/www/a.php:14 Fatal error: Uncaught Error: Typed property class@anonymous::$s must not be accessed before initialization in /var/www/a.php:14 Actual result: -------------- PHP Notice: Undefined property: class@anonymous::$i in /var/www/a.php on line 14 NULL PHP Notice: Undefined property: class@anonymous::$s in /var/www/a.php on line 14 string(0) "" ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=78809&edit=1