Doc #71051 [Sus->Nab]: Type Hint about SeekableIterator::seek does not match with informed

From: Date: Tue, 08 Dec 2015 20:24:48 +0000
Subject: Doc #71051 [Sus->Nab]: Type Hint about SeekableIterator::seek does not match with informed
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-12916@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=71051&edit=1 ID: 71051 Updated by: requinix@php.net Reported by: gabriel dot heming at hotmail dot com Summary: Type Hint about SeekableIterator::seek does not match with informed -Status: Suspended +Status: Not a bug Type: Documentation Problem Package: SPL related Operating System: Debian 8.2 PHP Version: 7.0.0 Block user comment: N Private report: N New Comment: @salathe just made bug #71058 so I'm closing this as NAB. Yes, you must remove the type hint for it to work. Built-in functions work differently than userland functions and the signature of a method (its name and parameter list) is separate from how parameters are typed. Currently the method signature does not include typing and is just "seek($position)" - that is what you need to match with your implementation. The fact that the manual shows "void seek(int $position)" is purely for documentation. I don't know what's broken but I'm talking about the assorted mailing lists. http://php.net/mailing-lists.php Previous Comments: ------------------------------------------------------------------------ [2015-12-08 11:08:08] gabriel dot heming at hotmail dot com What I do not understand is about my code, I must remove the type hint in order to work with them. In others reports, I saw about an internal mail, but the links was broken. There's something about it now? ------------------------------------------------------------------------ [2015-12-07 21:12:17] requinix@php.net Related To: Bug #71053 ------------------------------------------------------------------------ [2015-12-07 21:06:57] requinix@php.net >do not use type hinting By that I mean the function signatures. As in the types aren't defined in the signatures themselves. Obviously the code itself does respect strict typing. ------------------------------------------------------------------------ [2015-12-07 21:01:16] requinix@php.net Built-in functions and methods currently do not use type hinting. The documentation indicates the type as a clue to developers about the types of values used by each parameter, but the types themselves are not part of the signature. I'm suspending this pending discussion about what to do. ------------------------------------------------------------------------ [2015-12-07 13:17:05] gabriel dot heming at hotmail dot com Description: ------------ When I try match method assignature of my implementation of SeekableIterator, that one does not match with information from documentation. http://php.net/manual/en/seekableiterator.seek.php abstract public void SeekableIterator::seek ( int $position ); Test script: --------------- <?php declare(strict_types=1); class MySeekableIterator implements SeekableIterator { /** omitted properties and methods methods **/ /* Method required for SeekableIterator interface */ public function seek(int $position) { if (!isset($this->array[$position])) { throw new OutOfBoundsException("invalid seek position ($position)"); } $this->position = $position; } } Expected result: ---------------- Nothing. Should be exactly one as documentation. Actual result: -------------- Declaration of MySeekableIterator::seek(int $position) must be compatible with SeekableIterator::seek($position) If I omit the type hint, works fine. But documentation give me other information, as appended above. ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=71051&edit=1

« previous php.doc.bugs (#12916) next »