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
 [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: Mon Dec 30 14:01:28 2024 UTC