Edit report at https://bugs.php.net/bug.php?id=60338&edit=1

 ID:                 60338
 Comment by:         le...@php.net
 Reported by:        g...@php.net
 Summary:            SplFixedArray::key returns index for invalid keys
 Status:             Open
 Type:               Bug
 Package:            SPL related
 PHP Version:        5.4SVN-2011-11-19 (SVN)
 Block user comment: N
 Private report:     N

 New Comment:

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.


Previous Comments:
------------------------------------------------------------------------
[2011-11-19 13:38:53] g...@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] g...@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

Reply via email to