Re: PHP 7.1 - Address PHPSadness #28?
| From: | Robert Williams | Date: | Wed, 16 Sep 2015 17:37:09 +0000 |
| Subject: | Re: PHP 7.1 - Address PHPSadness #28? | ||
| References: | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-88252@lists.php.net to get a copy of this message | ||
On Sep 16, 2015, at 06:54, Rowan Collins <rowan.collins@gmail.com> wrote:
>
> I want to pull this out for a bit more attention: one of the crucial questions in this thread
> is whether the language is wrong, or just the documentation. There's one particularly wonky
> passage someone found in the manual that makes it sound like unitialised variables have an intrinsic
> type when accessed, rather than just referring the reader to the rules on casting null to any given
> type; when I have time, I will find and reword it.
The docs suggest that uninitialized variables are null, and the above makes it sound like that’s
what you’re stating, too. But they’re not: they don’t exist at all, they’re uninitialized.
If they were null, then PHP wouldn’t spit out errors about undefined variable accesses because it
would see them as the same thing as a (perfectly legal) null variable access. Differentiating these
various cases is currently a little wonky, requiring some extra boilerplate code and/or ugly-ish
workarounds (like calling get_defined_vars()). I don’t think it’s a huge gap in the language,
but it’s a definite gap, and it’s one that many less-experienced programmers fall right into
with safety checks.
-Bob
Attachment: [application/pgp-signature] Message signed with OpenPGP using GPGMail signature.asc
Attachment: [application/pgp-signature] Message signed with OpenPGP using GPGMail signature.asc