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
 [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 06 22:01:31 2024 UTC