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]

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to