#41682 [Opn->Bgs]: offsetGet() returns a VALUE, given a KEY

From: Date: Wed, 13 Jun 2007 19:33:28 +0000
Subject: #41682 [Opn->Bgs]: offsetGet() returns a VALUE, given a KEY
References: 1  Groups: php.doc 
Request: Send a blank email to phpdoc+get-969376658@lists.php.net to get a copy of this message
ID: 41682 Updated by: gwynne@php.net Reported By: acallaha at connect dot carleton dot ca -Status: Open +Status: Bogus Bug Type: Documentation problem Operating System: Fedora PHP Version: Irrelevant New Comment: This is expected behavior for ArrayObject:offsetGet(). The array in your reproduce code has only associative keys, so there is no value at the integer index 2: $ php <?php $array_3=array("this"=>"0", "is"=>"1", "life"=> "hello"); $array_3_obj = new ArrayObject($array_3); print $array_3_obj->offsetGet(2)."\n"; print $array_3_obj->offsetGet("is")."\n"; $array_4_obj = new ArrayObject(array("0","1","hello")); print $array_4_obj->offsetGet(2)."\n"; ?> ^D Notice: Undefined offset: 2 in - on line 4 1 hello $ If you truly want the third element of an associative array regardless of key, you may be looking for ArrayIterator. Previous Comments: ------------------------------------------------------------------------ [2007-06-13 18:58:40] acallaha at connect dot carleton dot ca Description: ------------ ArrayObject::offsetGet() does NOT return the value corresponding to a given index as documented, but actually requires a key (NOT an int $index) as input and returns a value given this key. This was determined through testing. Reproduce code: --------------- A sample array: $array_3=array("this"=>"0", "is"=>"1", "life"=> "hello"); $array_3_obj = new ArrayObject($array_3); print $array_3_obj->offsetGet(2); Expected result: ---------------- hello Actual result: -------------- PHP Notice: Undefined offset: 2 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=41682&edit=1

« previous php.doc (#969376658) next »