> On Sep 16, 2015, at 14:57, Stanislav Malyshev <smalys...@gmail.com> wrote:
> 
>> I’ll refer again to the above documentation:
>> 
>> "A variable is considered to be null if […] it has been unset().”
> 
> You are confusing two things.
> 
> 1. The variable has value of null.
> 2. The variable does not exist, so when you try to get its value,
> there's nothing to give you, but we don't want to produce fatal error
> because of such trifle, so we substitute null instead.

Nothing confused here. If the variable doesn’t exist, then it doesn’t exist, 
and accessing it rightly produces an error (albeit a low-grade error). PHP 
gives you a token null to be nice, but the fact is, you still committed an 
error by trying to access something that doesn’t exist. I’m fine with all of 
that, but I also would like to have the option of easily knowing about the 
problem before I hit it.

And, although you may not care whether the provenance of a variable’s null lies 
in buggy code or in explicit programmer/user decision, I consider that an 
extremely important distinction. It’s the difference between, “What the hell, 
delete anyway. They can always do the work again.” and, “Okay, we’ve got a 
signed delete order from the user, so delete away."

>> This one can’t be chalked up to sloppy writing. Here, something is just
>> plain wrong.
> 
> I'm afraid the something which is wrong here is your understanding of
> how undefined variables and nulls work :) "Considered to" is not the
> same as "is". It's a substitution, not identity.

I understand it just fine, thank you, but I disagree with your forgiveness of 
the docs. An unset variable is not null. Rather, it’s completely undefined, and 
PHP yells at you for just that reason if you try to access it. Then, it turns 
around and tries to appease you by giving you null. If it changed it to null on 
access and never threw the error, your statement would be more accurate, but 
that’s not what happens.

For the record, I’d actually prefer that PHP throw a fatal error if you access 
an undefined variable because it almost always means that your code is working 
with junk data. Right along with that, however, I’d like a way to easily tell 
that my data is bad (i.e., a variable hasn’t been defined) so that I can 
gracefully handle the problem and avoid the fatal.

-Bob

Attachment: signature.asc
Description: Message signed with OpenPGP using GPGMail

Reply via email to