像这样的代码:
interface entite
{
}
class Foo implements entite
{
}
$foo = new foo;
if( $foo instanceof entite ) echo "he is";
显示“他是”。Foo 从接口继承类型“entite”但是当尝试:
class FooDeleter implements deleter
{
public function __construct(Foo $Foo)
{
}
}
interface deleter
{
public function __construct(entite $entite);
}
给我 :
Fatal error: Declaration of FooDeleter::__construct() must be compatible with deleter::__construct(entite $entite)
为什么 ?如何 ?=(
编辑:独特的方式实际上是像这样定义类型化的删除器:
class FooDeleter implements deleter
{
public function __construct(entite $Foo)
{
if( $Foo instanceof Foo ) { ... }
}
}