Bug #60338 [Asn->Wfx]: SplFixedArray::key returns index for invalid keys
Edit report at https://bugs.php.net/bug.php?id=60338&edit=1
ID: 60338
Updated by: nikic@php.net
Reported by: gooh@php.net
Summary: SplFixedArray::key returns index for invalid keys
-Status: Assigned
+Status: Wont fix
Type: Bug
Package: SPL related
PHP Version: 5.4SVN-2011-11-19 (SVN)
Assigned To: levim
Block user comment: N
Private report: N
New Comment:
Agree with Levi: The return value of key() and other Iterator methods on an invalidated iterator is
undefined.
Previous Comments:
------------------------------------------------------------------------
[2013-09-21 23:38:49] levim@php.net
I personally don't see why we should bring this into line with array, ArrayObject
and ArrayIterator behavior. The fact of the matter is simple: you are calling
key() on an iterator that is not in a valid state; therefore the behavior is
undefined. The fact that array and the other classes you mention return NULL is
an implementation detail, the only one of which I believe is guaranteed is the
case of an array.
------------------------------------------------------------------------
[2011-11-19 13:38:53] gooh@php.net
Apparently the Expected Output is achieved when using key() instead of SplFixedArray::key(). See http://codepad.viper-7.com/I3REjD. Thanks to NikiC for
pointing it out.
------------------------------------------------------------------------
[2011-11-19 13:32:44] gooh@php.net
Description:
------------
SplFixedArray::key() will return a value even when the key does not exist in the SplFixedArray. This
does not conform to the behavior we have in regular arrays, ArrayObject and ArrayIterator.
SplFixedArray::key() should return NULL when the current key does not exist to conform.
Test script:
---------------
http://codepad.viper-7.com/4hWmUn
Expected result:
----------------
NULL NULL NULL NULL
Actual result:
--------------
int(3) NULL NULL NULL
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=60338&edit=1
Thread (4 messages)