Daniel Convissor wrote:
Paul:
On Thu, Jul 17, 2008 at 02:58:00PM -0400, [EMAIL PROTECTED] wrote:
isset($array[$key])
how's that different from array_key_exists?
isset() thinks NULL is not set. Similarly, empty() can be used for stuff
like this, but of course, it thinks NULL, 0, FALS
Paul:
On Thu, Jul 17, 2008 at 02:58:00PM -0400, [EMAIL PROTECTED] wrote:
>
> isset($array[$key])
> how's that different from array_key_exists?
isset() thinks NULL is not set. Similarly, empty() can be used for stuff
like this, but of course, it thinks NULL, 0, FALSE and "" are all the
same.
Daniel Convissor wrote:
Paul:
$value=$array[$key]
One right way to do this is:
if (array_key_exists($key, $array)) {
// Life is good.
$value = $array[$key];
} else {
// Erm, it doesn't exist. Now what?
// Typically either set to NULL or throw error.
}
--Dan
I second that. F
> Of course it is possible to create a class with this behavior using
> SPL, but that doesn't take care of the superglobals and there might be
> performance problems.
>
> -John Campbell
Well, I've got a 'framework' that I use for my own projects that I call "PHP
on Nails". It has several levels
> One right way to do this is:
>
> if (array_key_exists($key, $array)) {
> // Life is good.
> $value = $array[$key];
> } else {
> // Erm, it doesn't exist. Now what?
> // Typically either set to NULL or throw error.
> }
For a long time I've used
isset($array[$key])
how's that d
> operation works well, but I find it pretty obnoxious that:
>
> (1) This throws warnings on a missing keys if a certain bit is set in
> error_reporting, and
> (2) It's not possible to have strict checking of variable names without also
> turning on strict checking of array keys (which I'd usual
Paul:
> $value=$array[$key]
One right way to do this is:
if (array_key_exists($key, $array)) {
// Life is good.
$value = $array[$key];
} else {
// Erm, it doesn't exist. Now what?
// Typically either set to NULL or throw error.
}
--Dan
--
T H E A N A L Y S I S A N D S O L
I've been "cross-training" in a few languages and been thinking about
differences in semantics in dictionaries (associative arrays) in common
languages. I wrote an article at:
[javascript:void(0);/*1216316970142*/]
http://gen5.info/q/2008/07/17/the-semantics-of-dictionaries-maps-and-hashtables