On Sep 16, 2015, at 11:28, Stanislav Malyshev <smalys...@gmail.com> wrote: > >> 1 PHP defines null to include variables that have "not been set" 2 > > No, not really, PHP does not define that.
It does according to the docs: "A variable is considered to be null if […] it has not been set to any value yet." http://php.net/manual/en/language.types.null.php <http://php.net/manual/en/language.types.null.php> I think that’s more sloppy documentation (declared versus defined) as opposed to literal truth, but…. >> PHP also defines null to include variables that have been unset() > > No, PHP does not define anything like that. In fact, unset() means the > variable is destroyed and does not exist (of course, excepting refcount > etc. issues). Null does not feature in this story at all. I’ll refer again to the above documentation: "A variable is considered to be null if […] it has been unset().” This one can’t be chalked up to sloppy writing. Here, something is just plain wrong. All of the above does touch on the gap, though. Ignoring the docs and looking at actual behavior of PHP, it’s clear that an undefined variable behaves differently from one assigned null. One can easily tell if a variable is null, but one can’t easily tell if a variable is just not defined. That strikes me as an oversight especially given the fact that one can use unset() to make a variable once again undefined. Put another way, we can create and destroy, but we can’t identify existence. It’s a small gap in language design. There are workarounds, but they’re workarounds. > That's not a correct description. Correct description is that if you ask > for a variable and it is not defined, null value is substituted. That happens in the end, but not before an error is thrown. I want a one-keyword way to know that a variable is not defined without having to trip an error. > That's your opinion. Mine, for example, is that it is a very useful > feature. In any case, PHP is implemented this way, and there's no way to > change it while the result remaining PHP language. If it makes PHP > unsuitable for you, sorry, but that's what PHP is. I don't think it > makes a lot of sense to discuss changing basic semantics of PHP engine - > I don't think this is going to happen. At this point, I don’t think anyone is proposing changing the semantics of the engine, just filling a gap that lets one determine whether a variable has already been defined -- like one can already do for constants, functions, classes, array elements, and object properties. You may or may not have use for the functionality, but other people do, and adding a clean way to determine how PHP would regard a given variable doesn’t strike me as in any way promoting bad code even if you don’t personally use it. -Bob
signature.asc
Description: Message signed with OpenPGP using GPGMail