Andrea Faulds wrote on 15/10/2015 16:32:
Hi Rowan,

Rowan Collins wrote:
But why "invent" (as far as PHP is concerned) this new keyword of "void"
to mean exactly the same thing "null" already means - absence of a
definite value?

They don't mean exactly the same thing. null is a value to represent a lack of a value. But there's also the concept of *no value at all* (a missing variable, say). The closest we have to that in PHP already would actually be `unset`, but that's a strange choice given it's not what we use in documentation (function prototypes, PHP manual, PHPDoc, etc. use `void`), and it's tainted by the bizarro `(unset)` cast which casts to null.

Oh, lord, not this discussion again! PHP has no concept of a variable being in the "state" of unset; it has programmer hints to warn you if you read before writing, and a couple of odd constructs which let you access the current symbol table as a dictionary.

The manual has some weird wording in places which implies that a variable takes on a type when first used, but in practice the rule is much simpler: any variable which hasn't had a value assigned yet is considered to have the value NULL, and normal cast rules apply from there. The same is true of missing array keys, object properties, unset() variables, unspecified return values, etc, etc, etc. They are all NULL.

You could add a warning for "function foo() { return; } $a = foo();" to match "$x = []; $a = $x['foo'];", but $a would still unambiguously contain the value NULL in both cases, and outside of some odd applications like templating, it is *values* the program should be concerned with, not the *reason* for those values.

Regards,
--
Rowan Collins
[IMSoP]

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

Reply via email to