Skip to content

Add support for inheritance in #[Friend] #29

Open
@alek-as

Description

@alek-as

The library works very well for most of our use cases, thank you for creating it!

We've recently discovered that adding #[Friend] annotation with an interface as friend class will produce an error when the method is called from implementation classes.

See below for simple code snippet:

<?php

declare(strict_types=1);

namespace App;

use DaveLiddament\PhpLanguageExtensions\Friend;

interface Foo
{
}

class Bar
{
    #[Friend(Foo::class)]
    public function bar(): void
    {
    }
}

class Baz implements Foo
{
    public function baz(): void
    {
        $bar = new Bar();

        $bar->bar();
    }
}

Produced error:

------ ----------------------------------------------------------------------------------------------- 
  Line   src/Foo.php                                                                                    
 ------ ----------------------------------------------------------------------------------------------- 
  27     App\Bar::bar cannot be called from App\Baz, it can only be called from its friend(s): App\Foo  
 ------ -----------------------------------------------------------------------------------------------

Is this error intentional?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions