php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #69317 Incorrect LSP check when extending multiple interfaces
Submitted: 2015-03-27 14:01 UTC Modified: 2020-06-25 08:11 UTC
From: nikic@php.net Assigned:
Status: Open Package: Scripting Engine problem
PHP Version: master-Git-2015-03-27 (Git) OS:
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: nikic@php.net
New email:
PHP Version: OS:

 

 [2015-03-27 14:01 UTC] nikic@php.net
Description:
------------
<?php

class X {}

interface A extends IteratorAggregate {
    function getIterator() : X;
}

interface B extends IteratorAggregate, A {

}

Fatal error: Declaration of IteratorAggregate::getIterator() must be compatible with A::getIterator(): X in /home/nikic/php-src/t030.php on line 9

This happens because we first inherit the IteratorAggregate::getIterator() method and then check it against the A::getIterator() method - which is of course wrong.

This is a problem with return types, because they are not fully invariant - not sure if it might also be a problem for some things before PHP 7.


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-06-25 08:11 UTC] nikic@php.net
This problems still exists. It's also not clear how to fix it, especially with covariance in PHP 7.4. We no longer have a way to just pick the "more specific" method, because variance might be unresolved at the time.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 13:01:31 2024 UTC