- 实现trait方法可以有多个别名的功能 - 支持insteadof语法在trait列表中的顺序无关性 - 保持trait别名的原始方法功能 - 添加对继承中静态方法不匹配的检查 - 更新trait别名数据结构以支持别名列表 - 重构trait方法包装器为独立函数 - 修复trait方法别名处理逻辑错误pull/5/head
parent
72b80276ba
commit
09be0226cb
10 changed files with 257 additions and 54 deletions
@ -0,0 +1,15 @@ |
||||
<?php |
||||
|
||||
class InheritanceStaticParent |
||||
{ |
||||
public static function run(): void |
||||
{ |
||||
} |
||||
} |
||||
|
||||
class InheritanceStaticChild extends InheritanceStaticParent |
||||
{ |
||||
public function run(): void |
||||
{ |
||||
} |
||||
} |
||||
@ -0,0 +1,13 @@ |
||||
<?php |
||||
|
||||
interface InterfaceStaticContract |
||||
{ |
||||
public static function run(): void; |
||||
} |
||||
|
||||
class InterfaceStaticImpl implements InterfaceStaticContract |
||||
{ |
||||
public function run(): void |
||||
{ |
||||
} |
||||
} |
||||
@ -0,0 +1,29 @@ |
||||
--TEST-- |
||||
Trait alias keeps original method |
||||
--FILE-- |
||||
<?php |
||||
trait TraitAliasOriginal |
||||
{ |
||||
public function hello(): void |
||||
{ |
||||
echo "hello\n"; |
||||
} |
||||
} |
||||
|
||||
class TraitAliasOriginalUser |
||||
{ |
||||
use TraitAliasOriginal { |
||||
hello as hi; |
||||
} |
||||
} |
||||
|
||||
function main() |
||||
{ |
||||
$user = new TraitAliasOriginalUser(); |
||||
$user->hello(); |
||||
$user->hi(); |
||||
} |
||||
?> |
||||
--EXPECT-- |
||||
hello |
||||
hello |
||||
@ -0,0 +1,38 @@ |
||||
--TEST-- |
||||
Trait insteadof works regardless of trait list order |
||||
--FILE-- |
||||
<?php |
||||
trait TraitOrderA |
||||
{ |
||||
public function hello(): void |
||||
{ |
||||
echo "A\n"; |
||||
} |
||||
} |
||||
|
||||
trait TraitOrderB |
||||
{ |
||||
public function hello(): void |
||||
{ |
||||
echo "B\n"; |
||||
} |
||||
} |
||||
|
||||
class TraitOrderUser |
||||
{ |
||||
use TraitOrderB, TraitOrderA { |
||||
TraitOrderB::hello insteadof TraitOrderA; |
||||
TraitOrderA::hello as helloA; |
||||
} |
||||
} |
||||
|
||||
function main() |
||||
{ |
||||
$user = new TraitOrderUser(); |
||||
$user->hello(); |
||||
$user->helloA(); |
||||
} |
||||
?> |
||||
--EXPECT-- |
||||
B |
||||
A |
||||
@ -0,0 +1,32 @@ |
||||
--TEST-- |
||||
Trait method can have multiple aliases |
||||
--FILE-- |
||||
<?php |
||||
trait TraitMultipleAlias |
||||
{ |
||||
public function hello(): void |
||||
{ |
||||
echo "hello\n"; |
||||
} |
||||
} |
||||
|
||||
class TraitMultipleAliasUser |
||||
{ |
||||
use TraitMultipleAlias { |
||||
hello as hi; |
||||
hello as hey; |
||||
} |
||||
} |
||||
|
||||
function main() |
||||
{ |
||||
$user = new TraitMultipleAliasUser(); |
||||
$user->hello(); |
||||
$user->hi(); |
||||
$user->hey(); |
||||
} |
||||
?> |
||||
--EXPECT-- |
||||
hello |
||||
hello |
||||
hello |
||||
Loading…
Reference in new issue