RE: Re[2]: [PHP] Odd behaviour of non-existent keys?

From: Date: Wed, 25 Aug 2004 14:37:29 +0000
Subject: RE: Re[2]: [PHP] Odd behaviour of non-existent keys?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-194683@lists.php.net to get a copy of this message
Geoff Caplan wrote: > I think you are probably right - but this behaviour causes problems. > For example: > > $foo['one']['two'] = "test-string" ; > > // Evaluates to TRUE (not what's wanted!) > isset( $foo['one']['two']['three'] ) ; > > I need a reliable way to test for the non-existence of a > multi-dimensional key. Any ideas? I guess I could convert the keys > into a string via a loop and compare that, but there must be a more > elegant way, surely? IMHO what you have described is a bug in PHP, and if I were you, I'd report it as such. If it's not a bug it at least has a very high WTF factor. Having to use the cumbersome: is_array($foo['one']['two']) && array_key_exists('three', $foo['one']['two']) instead of: isset($foo['one']['two']['three']) seems kinda silly to me. I doubt that this is the intended behavior.

« previous php.general (#194683) next »