Robert Williams wrote on 16/09/2015 18:37:
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.
As soon as you access them, you will get the value null. You can do everything with them that you could do with a variable initialised to null.
If they were null, then PHP wouldn’t spit out errors about undefined variable accesses
Once again - PHP does not spit out errors when you access an undefined variable. It spits out Notices in case you've done it by mistake. Maybe you're thinking of JavaScript?
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.
There is no safety check required. If you care about eliminating the Notices, then initialise all your variables properly, and you will never have an uninitialised variable (so a runtime check for one would be pointless). If you don't care about eliminating the Notices, then simply treat uninitialised variables as Null, and they will work absolutely fine.
Regards, -- Rowan Collins [IMSoP] -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php