Bug #60338 [Com]: SplFixedArray::key returns index for invalid keys

From: Date: Sat, 21 Sep 2013 23:38:49 +0000
Subject: Bug #60338 [Com]: SplFixedArray::key returns index for invalid keys
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-181736@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=60338&edit=1

 ID:                 60338
 Comment by:         levim@php.net
 Reported by:        gooh@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] 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)

« previous php.bugs (#181736) next »