php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #65942 PHP Notice is fired if the specified $index does not exists
Submitted: 2013-10-22 01:11 UTC Modified: 2013-10-22 13:15 UTC
From: gontijo dot douglas at gmail dot com Assigned: daverandom (profile)
Status: Closed Package: Documentation problem
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
 [2013-10-22 01:11 UTC] gontijo dot douglas at gmail dot com
Description:
------------
---
From manual page: http://www.php.net/arrayobject.offsetget#refsect1-arrayobject.offsetget-returnvalues
---

It'll fire a PHP Notice if the specified $index does not exists

Test script:
---------------
<?php
// from http://www.php.net/manual/en/arrayobject.offsetget.php#example-3971
$arrayobj = new ArrayObject(array('zero', 7, 'example'=>'e.g.'));
var_dump($arrayobj->offsetGet(1));
var_dump($arrayobj->offsetGet('example'));
var_dump($arrayobj->offsetExists('notfound'));

// added by me
var_dump($arrayobj->offsetGet('notfound')); //shouldn't return null silently?


Expected result:
----------------
int(7)
string(4) "e.g."
bool(false)
NULL


Actual result:
--------------
int(7)
string(4) "e.g."
bool(false)
Notice: Undefined index: notfound in test.php on line 8
NULL

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-10-22 08:32 UTC] krakjoe@php.net
-Status: Open +Status: Not a bug
 [2013-10-22 08:32 UTC] krakjoe@php.net
This is expected behaviour; isset/offsetExists does not request a read of the element requested, only checks for it's presence. 

It would not be useful for isset/offsetExists to raise a warning; it is however expected that if you read from a non-existent element a warning will be raised, because you have not checked for the presence of the element but requested the elements data, which doesn't exist.
 [2013-10-22 10:23 UTC] bwoebi@php.net
-Status: Not a bug +Status: Open
 [2013-10-22 10:23 UTC] bwoebi@php.net
That actually is a documentation problem: the docs don't state that

(new ArrayObject([…]))->offsetGet('undefinedIndex');

can raise a notice upon not found index.
 [2013-10-22 10:40 UTC] daverandom@php.net
Automatic comment from SVN on behalf of daverandom
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=331907
Log: Document E_NOTICE emitted when an undefined index is supplied to ArrayObject::offsetGet(). Fix for bug #65942.
 [2013-10-22 10:41 UTC] daverandom@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: daverandom
 [2013-10-22 10:41 UTC] daverandom@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.


 [2013-10-22 13:15 UTC] gontijo dot douglas at gmail dot com
@krakjoe After asking the guys on freenode#php, they said the same thing, this is expected behaviour. So there was a documentation bug, as stated in Package and Bug Type.

@bwoebi thanks :)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri May 17 07:01:32 2024 UTC