php中final关键字用法分析

原创 2016-12-22 16:04:09 219
摘要:本文实例讲述了php中final关键字用法。分享给大家供大家参考,具体如下:final关键字只能用来定义类和定义方法。使用final关键字标记的类不能被继承final class Person{    ....... } class Student extends Person{    .

本文实例讲述了php中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()

更多关于php中final关键字用法-PHP程序员必知的文章请关注PHP中文网(www.php.cn)其它文章!

发布手记

热门词条