PHP isset bug or WAD!?

Consider the array
$a = array ( ‘Book’ => array ( ‘isbn’ => 1 ) );
var_dump ( isset($a[‘Book’][‘isbn’][‘bla_bla’]) ) will return TRUE ..
The isset function instead of check if there is an array index on that position, it don’t and returns TRUE for any value besides 0 or false, making a possible validation wrong and your logic to mess up.
The same happens with !empty function from PHP.
Is it a bug? Not really. both isset and  empty functions uses mixed as parameter and mixed means that the param can be anything, from a value to a array index.
This kind of stuff can make you have some troubleshooting fun for the longest of times.
Have fun!

About mcloide

Making things simpler, just check: View all posts by mcloide

4 responses to “PHP isset bug or WAD!?

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: