You are here: Re: [PHP] Type of form element « PHP « IT news, forums, messages
Re: [PHP] Type of form element

Posted by "Richard Lynch" on 10/31/05 19:55

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

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация