PHP final 키워드
PHP/매뉴얼 번역 2008/06/20 00:42PHP 5 에서 키워드 final 이 도입되어 final 을 앞에 붙여서 정의된 메소드는 자식 클래스를 오버라이딩 할 수 없다. 클래스 자체가 final 로 정의된 경우에는 클래스의 확장을 할 수 없다.
final 메소드 예
class BaseClass {
public function test() {
echo "BaseClass::test() called\n";
}
final public function moreTesting() {
echo "BaseClass::moreTesting() called\n";
}
}
class ChildClass extends BaseClass {
public function moreTesting() {
echo "ChildClass::moreTesting() called\n";
}
}
// Results in Fatal error: Cannot override final method BaseClass::moreTesting()
?>
final 클래스 예
final class BaseClass {
public function test() {
echo "BaseClass::test() called\n";
}
// Here it doesn't matter if you specify the function as final or not
final public function moreTesting() {
echo "BaseClass::moreTesting() called\n";
}
}
class ChildClass extends BaseClass {
}
// Results in Fatal error: Class ChildClass may not inherit from final class (BaseClass)
?>
원문링크:http://www.php.net/manual/en/language.oop5.final.php
목차에
PHP 클래스와 오브젝트 ( Classes and Objects ) PHP 5
'PHP > 매뉴얼 번역' 카테고리의 다른 글
| PHP 문자열 지정방법 ( Heredoc ) (0) | 2008/06/20 |
|---|---|
| PHP Late Static Bindings (0) | 2008/06/20 |
| PHP 타이프 힌팅 (0) | 2008/06/20 |
| PHP 오브젝트의 비교 (0) | 2008/06/20 |
| PHP 오브젝트의 클론 생성 (0) | 2008/06/20 |
| PHP final 키워드 (0) | 2008/06/20 |
| PHP 매직메소스 (0) | 2008/06/20 |
| PHP 패턴 (0) | 2008/06/20 |
| PHP 오브젝트 이터레이션 (0) | 2008/06/20 |
| PHP 오버로드 (0) | 2008/06/20 |
| PHP 오브젝트 인터페이스 (0) | 2008/06/20 |