Req #77518 [Com]: SeekableIterator::seek() should accept 'int' typehint as documented
| From: | fractalesque at gmail dot com | Date: | Thu, 24 Jan 2019 19:49:50 +0000 |
| Subject: | Req #77518 [Com]: SeekableIterator::seek() should accept 'int' typehint as documented | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-219183@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=77518&edit=1
ID: 77518
Comment by: fractalesque at gmail dot com
Reported by: claude dot pache at gmail dot com
Summary: SeekableIterator::seek() should accept 'int'
typehint as documented
Status: Open
Type: Feature/Change Request
Package: SPL related
PHP Version: 7.3.1
Block user comment: N
Private report: N
New Comment:
Hello,
unless I am mistaken, the rfc you link has been passed allowing for type hints to be _widened_, that
is, that declaring an untyped variable could pass a typed variable, whereas what you are doing is
the inverse.
That is, if the interface was typed with int, you could implement it without the int, but not add
the int where the interface declares untyped.
Previous Comments:
------------------------------------------------------------------------
[2019-01-24 19:11:01] claude dot pache at gmail dot com
Description:
------------
This is related to Bug #71051, but since
https://wiki.php.net/rfc/parameter-no-type-variance
has been implemented, it should be fixable in PHP7.2+ without breaking legacy code.
Per documentation, the signature of SeekableIterator::seek() is:
abstract public SeekableIterator::seek ( int $position ) : void
However, when implementing the interface, providing the typehint âintâ triggers a compile
error.
Test script:
---------------
class Foo implements SeekableIterator {
function current() { }
function key() { }
function next() { }
function rewind() { }
function valid() { }
function seek(int $position) { }
}
Expected result:
----------------
No error.
Actual result:
--------------
Fatal error: Declaration of Foo::seek(int $position) must be compatible with
SeekableIterator::seek($position)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=77518&edit=1