php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #62727 ArrayObject::offsetGet return type/logic error
Submitted: 2012-08-02 17:56 UTC Modified: 2013-10-09 06:26 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: sandy at figureone dot com Assigned: krakjoe (profile)
Status: Closed Package: Documentation problem
PHP Version: 5.4.5 OS: All
Private report: No CVE-ID: None
 [2012-08-02 17:56 UTC] sandy at figureone dot com
Description:
------------
The docs for ArrayObject::offsetGet say it will return the value at the passed index or boolean FALSE.

http://www.php.net/manual/en/arrayobject.offsetget.php

This suggests some sort of graceful failure on an undefined index, returning the default value FALSE (never mind the possible ambiguity of this return vs. the stored value FALSE).

In actuality, it returns NULL for an undefined index and fires off the "Undefined index" NOTICE as with regular arrays.

Test script:
---------------
$t = new ArrayObject(array('exists'=>42));
var_dump( $t->offsetGet('non_existent') );

Expected result:
----------------
FALSE 

(and no notice)

Actual result:
--------------
NULL 

with

PHP Notice: Undefined index: non_existent in /code/2DUpLq on line 4

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-10-09 06:26 UTC] krakjoe@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: krakjoe
 [2013-10-09 06:26 UTC] krakjoe@php.net
The documentation no longer contains this discrepancy, so closing the bug.
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Tue Oct 06 03:00:02 2026 UTC