PHP Bugs  
php.net | support | documentation | report a bug | advanced search | search howto | statistics | login

go to bug id or search bugs for  

Bug #19080 Docs not clear on the diff between isset() and array_key_exists()
Submitted:23 Aug 2002 7:20pm UTC Modified: 28 Aug 2002 12:25pm UTC
From:andrey at webgate dot bg Assigned to:
Status:Closed Category:Documentation problem
Version:4.2.2 OS:All
View/Vote Developer Edit Submission

Welcome! If you don't have a SVN account, you can't do anything here. You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
SVN Username: SVN Password:
Quick Fix:
Status: Assign to:
Category:
Summary:
From: andrey at webgate dot bg
New email:
Version: OS:
New/Additional Comment:

[23 Aug 2002 7:20pm UTC] andrey at webgate dot bg
 Hello,
this code :
<?php 
$a = array(1=>NULL);
var_dump($a);
var_dump(isset($a[1]));
var_dump(array_key_exists(1,$a));
?>
Produces this :
array(1) {
  [1]=>
  NULL
}
bool(false)
bool(true)

So for first time I see difference in the use of isset() and
array_key_exists(). Many users (including me till 1 one ago) believe
that they are equivalent and because isset() is shorter it is mostly
used.
Should be there any notice in the docs about this issue?
This code is correct and the bug report was inspired by note to do this
by jmcastagnetto.

Regards,
Andrey
[28 Aug 2002 12:25pm UTC] kalowsky@php.net
There is an example in the docs explaining the difference between this
on the isset() page.  
[3 Oct 2003 8:35am UTC] mvivino at avaya dot com
After being "bitten" by this one myself, I looked back at the
documentation more carefully, and of course this is correct behavior, as
noted in the thread above.

The one-line summary of the function's behavior is still (IMHO) wrong: 

>> Returns TRUE if var exists; FALSE otherwise.

Simply rewriting this as:

>> Returns TRUE if var exists and is not set to NULL; FALSE otherwise.

would make the behavior crystal clear, and might save a few other folks
trouble in the future.

RSS feed | show source 

PHP Copyright © 2001-2009 The PHP Group
All rights reserved.
Last updated: Sat Nov 21 10:30:49 2009 UTC