|  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
Avg. Score:3.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: 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]
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:

Expected result:

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2011-11-19 13:38 UTC]
Apparently the Expected Output is achieved when using key() instead of SplFixedArray::key(). See Thanks to NikiC for pointing it out.
 [2013-09-21 23:38 UTC]
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]
-Assigned To: +Assigned To: levim
PHP Copyright © 2001-2015 The PHP Group
All rights reserved.
Last updated: Tue Dec 01 12:01:36 2015 UTC