Robert Williams wrote on 15/09/2015 10:38:
Okay, so to bring this home:
1 PHP defines null to include variables that have "not been set"
2 PHP also defines null to include variables that have been unset()
3 Variables can be explicitly set to null
All of these are null. And yet:
4 Calling isset(), which is documented to return true on null, on 1, 2, and 3
will only return true for 3.
How's this consistent?
What you've just described there is the functionality some people want
to add. Currently, isset() will return false for all three cases,
precisely because they are treated as equivalent. So you've actually
neatly demonstrated why it is consistent for isset() to behave as it does.
IMHO, PHP went south in its design when it tried to declare undefined variables
as null. They're not; they're undefined. Beyond isset/empty/is_null, however,
the rest of PHP seems to accept this.
"The rest of PHP" makes no such distinction. If you evaluate "$b = $a +
1" when $a is not defined, PHP behaves exactly as if you had written
"$a=null; $b = (int)$a + 1;", but the runtime will issue a notice (not,
as you keep claiming, an error) that you forgot to write the "$a=null"
part and might want to add it in or check if you've mistyped the
variable name.
Regards,
--
Rowan Collins
[IMSoP]
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php