[nycphp-talk] empty string as array key ?

Adam Maccabee Trachtenberg adam at
Fri Aug 8 10:21:52 EDT 2003

On Fri, 8 Aug 2003, David Mintz wrote:

> I just found out that this is legal
> $minutes = array(''=>" ","00"=>"00","30"=>"30"); //etc
> Is this  -- the fact that you can get away with using an
> empty string as an array key -- a bug or a feature (or neither)?

I believe it is a feature. The empty string is a valid string and
differentiable from NULL. In fact, if you are creative enough, you can
name variables (or array elements) all sorts of stupid names:

${"\n"} = 'return';
$a = compact("\n");

] => return


adam at
author of o'reilly's php cookbook
avoid the holiday rush, buy your copy today!

More information about the talk mailing list