php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #60338 SplFixedArray::key returns index for invalid keys
Submitted: 2011-11-19 13:32 UTC Modified: 2014-02-27 04:54 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: gooh@php.net Assigned: levim
Status: Assigned Package: SPL related
PHP Version: 5.4SVN-2011-11-19 (SVN) OS:
Private report: No CVE-ID:
Have you experienced this issue?
Rate the importance of this bug to you:

 [2011-11-19 13:32 UTC] 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 

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-11-19 13:38 UTC] 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.
 [2013-09-21 23:38 UTC] 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.
 [2014-02-27 04:54 UTC] levim@php.net
-Assigned To: +Assigned To: levim
 
PHP Copyright © 2001-2015 The PHP Group
All rights reserved.
Last updated: Wed Mar 04 22:02:12 2015 UTC