php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #62724 isset returns false but array_key_exists returns true (int keys)
Submitted: 2012-08-02 09:36 UTC Modified: 2012-08-02 09:47 UTC
From: max at kriegt dot es Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 5.4.5 OS: Debian 6
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
10 + 30 = ?
Subscribe to this entry?

 
 [2012-08-02 09:36 UTC] max at kriegt dot es
Description:
------------
Hi,

recently realized that isset not returning the same result as array_key_exists 
does for int-Keys.

Test script:
---------------
<?php
$foo = array(null);

var_dump( isset($foo[0]), array_key_exists(0, $foo) );

Expected result:
----------------
bool(true)
bool(true)

Actual result:
--------------
bool(false)
bool(true)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-08-02 09:43 UTC] keithm at aoeex dot com
This is not a bug.  From the manual page on isset:
"Determine if a variable is set and is not NULL."

In your example, $foo[0] is null which is why isset returns false.
 [2012-08-02 09:46 UTC] aharvey@php.net
-Status: Open +Status: Not a bug
 [2012-08-02 09:46 UTC] aharvey@php.net
What Keith said. :)
 [2012-08-02 09:47 UTC] max at kriegt dot es
Hm - misinterpreted the function. :/
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon May 27 04:01:31 2024 UTC