TypePHP 编译器 https://swoole.com/aot/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

38 lines
757 B

--TEST--
Trait method with `self` return type flattened into a class that implements an interface declaring `self` return
--FILE--
<?php
interface TestInterface
{
public function test(): self;
}
trait TestTrait
{
public function test(): self
{
return $this;
}
}
class TestClass implements TestInterface
{
use TestTrait;
}
function main()
{
$test = new TestClass;
// The trait method's `self` resolves to the consuming class (TestClass),
// which must be compatible with the interface's `self` (TestInterface).
$result = $test->test();
var_dump($result instanceof TestClass);
var_dump($result === $test);
var_dump($result instanceof TestInterface);
}
?>
--EXPECT--
bool(true)
bool(true)
bool(true)