我们为大家收集整理了关于php中final关键字用法,以方便大家参考。final的意思是不可更改的,也就是说final定义的东西是不可改变的。
final关键字只能用来定义类和定义方法
使用final关键字标记的类不能被继承
final class Person{
.......
}
class Student extends Person{
.......
}
会出现错误提示。Fatal error :Class Student may not inherit from final class(Person)
使用final关键字标记的方法不能被子类覆盖
class Person{
final function Say(){
......
}
}
class Student extends Person{
function Say(){
......
}
}
会出现下面错误:
Fatal Error:Cannot Override final method Person::say()
来源: