php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #49889 offsetExists wrong result
Submitted: 2009-10-15 12:31 UTC Modified: 2010-04-25 07:25 UTC
From: carmen at helderhosting dot nl Assigned: colder (profile)
Status: Wont fix Package: SPL related
PHP Version: 5.3.0 OS: unix
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2009-10-15 12:31 UTC] carmen at helderhosting dot nl
Description:
------------
If $o = new ArrayObject(); $o['x'] = null;
the result for isset($o['x']) it should be false, instead true is given

Reproduce code:
---------------
<?php
$a = array();
$a['x'] = null;
var_dump(isset($a['x']));
var_dump(empty($a['x']));
var_dump(array_key_exists('x', $a));

$o = new ArrayObject();
$o['x'] = null;
var_dump($o->offsetExists('x'));
var_dump(isset($o['x']));
var_dump(empty($o['x']));
var_dump(array_key_exists('x', $o));
?>

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

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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-04-25 07:25 UTC] colder@php.net
-Status: Assigned +Status: Wont fix
 [2010-04-25 07:25 UTC] colder@php.net
Indeed, this feels a bit odd. However, isset() internally calls offsetExists, so 
if offsetExists returns true(and it should) on NULLs, then isset() will also 
return true. Three options at hand:

1) Modify offsetExists semantics to return false on NULLs, or
2) add another magic method called by isset().
3) Modify the semantics of isset() on objects to also call offsetGet and check 
the value, like empty.

For which I have at least one objection each:

1+3) counter-intuitive, and would break BC
2) not worth it, given that isset() is the only special case.

I believe that this is a "won't fix" scenario, sorry.
 
PHP Copyright © 2001-2017 The PHP Group
All rights reserved.
Last updated: Sun Nov 19 01:31:42 2017 UTC