Example #1 Final 方法示例
class BaseClass { public function test(){ echo "BaseClass::test() called<br>"; } final public function moreTesting(){ echo "BaseClass::moreTesting() called<br>"; } } class ChildClass extends BaseClass { public function moreTesting(){ echo "BaseClass::moreTeing called<br>"; } }
Example #2 Final 类示例
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。
- 本文固定链接: https://zxbcw.cn/post/1175/
- 转载请注明:必须在正文中标注并保留原文链接
- QQ群: PHP高手阵营官方总群(344148542)
- QQ群: Yii2.0开发(304864863)