php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #78517 Unable to connect two libraries where developer wants to return typehint
Submitted: 2019-09-09 10:23 UTC Modified: 2019-09-09 10:26 UTC
From: 6562680 at gmail dot com Assigned: nikic (profile)
Status: Closed Package: Reflection related
PHP Version: 7.2.22 OS: Win10
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: 6562680 at gmail dot com
New email:
PHP Version: OS:

 

 [2019-09-09 10:23 UTC] 6562680 at gmail dot com
Description:
------------
Maybe i understand interfaces incorrect but i think that we:
1. Create library
2. Create interface inside library
3. Upload library somewhere (composer)
4. Require library to project
5. Create interface in project for library wrapper
6. Will check our own interface inside project - library should match both interfaces and return instance that match both interfaces

But sometimes we need to extend library or just change some functions using `extend`. We want to change return type to our own interface and we cant, because return checker wont check interface, just compare strings

Test script:
---------------
<?php

interface iA {};
class A implements iA
{
    public function test() : self
    // public function test() : A // or maybe direct class
    // public function test() : iA // or maybe interface
    {
        return true;
    }
}

interface iB {};
class B extends A implements iB
{
    // public function test() : self // wtf? incorrect
    // public function test() : B // wtf? incorrect
    // public function test() : iA // works but requires `use` everywhere
    public function test() : A // works but requires `use` everywhere
    {
        return true;
    }
}

var_dump(new B);


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-09-09 10:24 UTC] 6562680 at gmail dot com
ps.
5*. usually we copy library interface to project like laws copies contracts or like businessman copy job offer contract
 [2019-09-09 10:26 UTC] nikic@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: nikic
 [2019-09-09 10:26 UTC] nikic@php.net
This is called "covariant return types" and will be supported in PHP 7.4.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 30 13:01:32 2024 UTC