Re: Type of form element

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, October 31, 2005 4:38 am, Marcus Bointon wrote:
> On 31 Oct 2005, at 06:18, Richard Lynch wrote:
>
>> But I really do believe isset($_POST['checkbox_name']) is a "good"
>> coding practice.
>
> OK, so PHP may not pass through unset params as NULL (it's not up to
> the browser), but if you don't select any checkboxes at all, the
> param won't exist, and asking for an index of something that doesn't
> exist is normally a good way to generate notices. isset's job is not
> to tell you if an array key exists, so why use it for that purpose?

You're wrong.

isset() does not, under any circumstances, create an index nor a
variable.

Its entire purpose *IS* to tell you if something has been set to a value.

That's why it's CALLED "isSet"

> This is the difference I'm on about:
>
> $z = array('a' => 1, 'b' => NULL);
> echo array_key_exists('a', $z)?"yes\n":"no\n";
> echo isset($z['a'])?"yes\n":"no\n";
> echo array_key_exists('b', $z)?"yes\n":"no\n";
> echo isset($z['b'])?"yes\n":"no\n";
>
> This prints:
>
> yes
> yes
> yes
> no
>
> That last 'no' has huge bug potential.

I really don't want to argue with you about the semantics of NULL,
but, as far as I'm concerned, the number of places where a NULL value
existing in an array should have meaning are essentially... NULL

If your code relies on NULL as a value in an array and the key
thereof, I'd guess that you're probably using the wrong data
structure, algorithm, or query in the first place.

But that's just me. [shrug]

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux