Doc #65942 [Csd]: PHP Notice is fired if the specified $index does not exists

From: Date: Tue, 22 Oct 2013 13:15:51 +0000
Subject: Doc #65942 [Csd]: PHP Notice is fired if the specified $index does not exists
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-10523@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=65942&edit=1 ID: 65942 User updated by: gontijo dot douglas at gmail dot com Reported by: gontijo dot douglas at gmail dot com Summary: PHP Notice is fired if the specified $index does not exists Status: Closed Type: Documentation Problem Package: Documentation problem PHP Version: Irrelevant Assigned To: daverandom Block user comment: N Private report: N New Comment: @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 :) Previous Comments: ------------------------------------------------------------------------ [2013-10-22 10:41:19] 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 10:40:31] 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:23:27] 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 08:32:23] 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 01:11:16] 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 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=65942&edit=1

« previous php.doc.bugs (#10523) next »