PHP 5 ������һ�� final �ؼ��֡���������еķ���������Ϊ final�������������Ǹ÷��������һ���౻����Ϊ final�����ܱ��̳С�
Example #1 Final ����ʾ��
<?php
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()
?>
Example #2 Final ��ʾ��
<?php
final class BaseClass {
public function test() {
echo "BaseClass::test() called\n";
}
// �����������Ƿ�������Ϊfinal����û�й�ϵ
final public function moreTesting() {
echo "BaseClass::moreTesting() called\n";
}
}
class ChildClass extends BaseClass {
}
// ���� Fatal error: Class ChildClass may not inherit from final class (BaseClass)
?>
Note: ���Բ��ܱ�����Ϊ final��ֻ����ͷ������ܱ�����Ϊ final��