메소드 만 정의하고 구현은 정의하지 않는 추상 클래스를 사용할 수 있습니다. 이 메소드 구현을 구현해야하는 경우
abstract class Mother
{
public function doSomething();
}
class Child implements Mother
{
public function doSomething()
{
echo 'Hello world';
}
}
$mother = new Mother(); // won't work
$child = new Child(); // works
$child->doSomething(); // echoes hello world
또는, 당신은 보호 생성자를 사용할 수 있습니다 (기능은 뭔가를하지만 그들은 오버로드 할 수 있습니다).
class Mother
{
protected function __construct()
{
echo "Hello World!";
}
}
class Child extends Mother
{
public function __construct()
{
parent::__construct();
}
}
$mother = new Mother(); // won't work, you're trying to access protected method
$child = new Child(); // it'll work echoing "Hello World!"
직접 질문과 관련된하지만`클래스 아이 Mother` 날에도 당신이 실제로 않는 이유도 말해 줄 수 ;-)
너 한테 붉은 깃발을 얹어 라? – VolkerK
을하려고하는지 모른 채 붉은 깃발을 제기 할 수 확장하지 –