php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #71051 Type Hint about SeekableIterator::seek does not match with informed
Submitted: 2015-12-07 13:17 UTC Modified: 2015-12-08 20:24 UTC
From: gabriel dot heming at hotmail dot com Assigned:
Status: Not a bug Package: SPL related
PHP Version: 7.0.0 OS: Debian 8.2
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: gabriel dot heming at hotmail dot com
New email:
PHP Version: OS:

 

 [2015-12-07 13:17 UTC] 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.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-12-07 21:01 UTC] requinix@php.net
-Status: Open +Status: Suspended
 [2015-12-07 21:01 UTC] 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 21:06 UTC] 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-08 11:08 UTC] 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-08 20:24 UTC] requinix@php.net
-Status: Suspended +Status: Not a bug
 [2015-12-08 20:24 UTC] requinix@php.net
@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
 [2015-12-09 13:55 UTC] gabriel dot heming at hotmail dot com
Thanks for your reply.

By this way, I lose (or my code) a little of strictness what I want about my code.

There's no way to make the assignature (for type hints) like variables names, what that doesn't matter at all?

Like:
public function seek($p) {

The code above, without match variable name (using $p instead of $position), will work normaly.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 11:01:30 2024 UTC