Re: [RFC][Vote] Typed Properties
| From: | Rowan Collins | Date: | Thu, 26 May 2016 09:44:40 +0000 |
| Subject: | Re: [RFC][Vote] Typed Properties | ||
| References: | 1 2 3 4 5 6 7 8 9 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-93553@lists.php.net to get a copy of this message | ||
On 25/05/2016 22:03, Fleshgrinder wrote:
We already have the differentiation between IS_NULL and IS_UNDEF, why not expose the latter to userland?I wondered if the conversation would go in this direction. This has been discussed to death, and in my opinion all the reasons given in previous discussions why isset() is not broken, and we do not need a new magic value / type, are just as valid in the case of object properties as anywhere else. I can see an advantage to this raising some kind of warning: class A { ?int $foo } $a = new A; var_dump($a->foo); // not initialized yet! But it should absolutely not be possible to detect the difference between that and this: class A { ?int $foo } $a = new A; $->foo = null; var_dump($a->foo); // null Because that is exactly the same as this: var_dump($foo); // not initialized yet! vs this: $foo = null; var_dump($foo); The warning or error on unitialized variables or properties is an assertion - code should be written such that it simply *can't* happen. If you're unsure if something's set, you can always do this: if ( ! isset($this->foo) ) { $this->foo = null; } If it's already an explicit null, you perform one unnecessary operation; if it's never been initialized, it has now. Regards, -- Rowan Collins [IMSoP]