php-language-extensions
php-language-extensions copied to clipboard
Add support for inheritance in #[Friend]
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?