PHP 手冊
上一頁 | 章 14.Classes and Objects (PHP 5) | 下一頁

# Final Keyword

PHP 5 introduces the final keyword, which prevents child classes from overriding a method or variable by prefixing the definition with final.

示範 14-17.Final methods example

`<?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() ?>`

上一頁 | 最開頭 | 下一頁
Magic Methods | 上一層 | Object cloning