Req #70016 [Opn]: SplDoublyLinkedList returns NULL for key()
| From: | cmb@php.net | Date: | Tue, 18 Aug 2015 22:43:29 +0000 |
| Subject: | Req #70016 [Opn]: SplDoublyLinkedList returns NULL for key() | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-195311@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=70016&edit=1
ID: 70016
Updated by: cmb@php.net
Reported by: me at evertpot dot com
Summary: SplDoublyLinkedList returns NULL for key()
Status: Open
Type: Feature/Change Request
Package: SPL related
Operating System: Any
PHP Version: 5.5.26
Block user comment: N
Private report: N
New Comment:
> current, next and key work on every Traversable.
Albeit not necessarily in a meaningful way, see
<https://3v4l.org/4EZrT>.
> The signature in the docs is simply *also* a bug, albeit a
> documentation bug.
Well, I don't think so, because key() internally expects a
HashTable as argument[1]. Passing an arbitrary Traversable might
cause undesirable overhead (and maybe worse; consider generators).
Anyway, as you are insisting that this is a bug, I'm changing back
to bug.
[1] <https://github.com/php/php-src/blob/php-5.6.12/ext/standard/array.c#L928-L937>
Previous Comments:
------------------------------------------------------------------------
[2015-08-18 21:39:14] me at evertpot dot com
current, next and key work on every Traversable. The signature in the docs is simply *also* a bug,
albeit a documentation bug.
See here for an alternative example using ArrayAccess:
https://3v4l.org/j0ab9
This has been a PHP feature since the introduction of Iterator.
------------------------------------------------------------------------
[2015-08-18 18:44:28] cmb@php.net
This is not a bug, see the signature of key():
| mixed key ( array &$array )
------------------------------------------------------------------------
[2015-07-08 03:49:36] me at evertpot dot com
Description:
------------
See code sample =)
Test script:
---------------
<?php
$foo = new SplDoublyLinkedList();
$foo->push('A');
$foo->push('B');
var_dump($foo->key());
var_dump(key($foo));
Expected result:
----------------
int(0)
int(0)
Actual result:
--------------
int(0)
NULL
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=70016&edit=1