interface entite
{
}
class Foo implements entite
{
}
$foo = new foo;
if($foo instanceof entite) echo "he is";
표시 "라고이다". 푸 인터페이스 에서 유형 "entite을"상속하지만 때 시도 :
Fatal error: Declaration of FooDeleter::__construct() must be compatible with deleter::__construct(entite $entite)
이유 :
class FooDeleter implements deleter
{
public function __construct(Foo $Foo)
{
}
}
interface deleter
{
public function __construct(entite $entite);
}
나에게 준다? 어떻게 ? = (
편집 : 당신이 인터페이스를 위반하는 인터페이스보다 더 엄격한 타입 힌트로 FooDeleter
생성자를 선언함으로써
class FooDeleter implements deleter
{
public function __construct(entite $Foo)
{
if($Foo instanceof Foo) { ... }
}
}
"OOP 인터페이스"를 원하십니까? –
이것은 Big Brown Book of PHP의 예제 코드입니다. –
저는 PHP가 당신이 인터페이스에서 생성자를 정의 할 수있게 해주었습니다. 나에게 끔찍한 생각처럼 보입니다. 관련된 질문은 여기에 - http://stackoverflow.com/questions/783046/constructor-methods-in-interfaces – Phil