On 26 Aug 2015, at 16:06, Rowan Collins <rowan.coll...@gmail.com> wrote:

> Craig Francis wrote on 26/08/2015 14:53:
>> On 26 Aug 2015, at 12:36, Rowan Collins <rowan.coll...@gmail.com> wrote:
>> 
>>> Fortunately, the function you are looking for already exists: 
>>> http://php.net/array_key_exists
>> It does, although I seem to have edited that out of my reply... was trying 
>> to keep it short ;-)
> 
> You could have kept the reply even shorter by omitting examples for which the 
> language already provides the solution ;)


I provide examples to help explain that I (and I suspect most developers) 
default to using isset which works on either.

Just because there is a function, which does not exactly roll off the tongue 
(plus the fun of the needle/haystack ordering issue), does not mean it gets 
used (even if it is the correct thing to use).




>> At the moment I'm out of examples (bit busy at the moment), but I do know 
>> that when I'm doing an isset() check, I'm really wanting to know if the 
>> variable (or key) exists
> 
> Stop. As soon as you say "or key" you completely defeat your argument. The 
> whole thing is ONLY worth discussing if you can come up with an example of an 
> actual variable having unknown existence.


I say "or key" because developers use the isset function on both $var and 
$var['key']... yes, I know they are different, but when you are coding in PHP 
an isset check is an isset check (well it isn't, because the variable may 
technically exist).

If this is a problem, maybe PHP should raise a notice when isset is used on 
arrays?




>> where NULL may be a perfectly valid value.
> 
> It's not that NULL isn't a valid value; it's that "doesn't exist" isn't a 
> meaningful state for a variable. It's like checking if the current line 
> number is greater than 100, it shouldn't mean anything to the compiled 
> program. See the SO answer I linked earlier for more thought experiments 
> along these lines.


I think you have been spending too much time in C.

Most of the PHP code bases I've worked on set variables to NULL at some point 
(and they are not calling unset, because that isn't the intention).


--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to