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

Posted by Chris Shiflett on 10/31/05 19:18

Marcus Bointon wrote:
> The thing I was wrong on is that PHP converts unset parameters (as
> opposed to nonexistent ones which it obviously can't do anything
> about) to an empty string, e.g. given ?a=&b=1, $_REQUEST ['a'] is
> "", not NULL.

That's right, except we seem to have a vocabulary discrepancy:

1. To me, "unset" and "not set" are not the same thing (sort of like how
"untie" and "not tied" are also not the same). I'm assuming you always
mean "not set" in your comments. Otherwise, it sounds like you're
describing some sort of conversion from one state to another. PHP is
just taking what it is given.

2. Given the above assumption, there is no difference between something
not being set and something not existing.

If you want to distinguish between $_GET['a'] and $_GET['b'] in your
example above, empty() does the trick. Some people use strlen() if they
want to also distinguish between the string 0 and the empty string, and
you can always just compare something to the empty string.

> However, it still serves to underline my other point that using
> isset without actually knowing that is a potentially dangerous
> thing.

I think Richard knew what he was doing. :-) If his approach is wrong,
then so is mine, because I also use isset() to see whether a checkbox
was checked. If you go back to my previous example, you'll see that array

> Getting into the habit of using it for looking in the likes of
> $_REQUEST means you're likely to use it other places where you
> have no such guarantee, and you'll have a bug to track down.
> Using array_key_exists means you will never be exposed to this
> possibility, no matter where your data comes from.

I understand and appreciate your argument. However, you're now
describing a social issue, not a technical one. These issues tend to be
more subjective, so "right" answers are difficult to find. :-)

In this case, the only concern would be that PHP considers something set
to NULL to be the same as not being set at all (as far as isset() is
concerned). This situation can never exist with things like $_GET and
$_POST, because everything in those arrays is a string.

Hope that helps.

Chris

--
Chris Shiflett
Brain Bulb, The PHP Consultancy
http://brainbulb.com/

 

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

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