Home  >  Article  >  Backend Development  >  How to use the final keyword in Guantu in PHP

How to use the final keyword in Guantu in PHP

小云云
小云云Original
2018-03-29 16:04:071287browse

The example in this article describes the usage of the final keyword in php. It is mainly explained to you in the form of code and shared with you for your reference. The details are as follows:

The final keyword can only be used to define classes and define methods.

Classes marked with the final keyword cannot be inherited

final class Person{
   .......
}
class Student extends Person{
   .......
}

An error message will appear. Fatal error: Class Student may not inherit from final class (Person)

Methods marked with the final keyword cannot be overridden by subclasses

class Person{
   final function Say(){
     ......
   }
}
class Student extends Person{
  function Say(){
    ......
  }
}

The following error will occur:

Fatal Error: Cannot Override final method Person::say()

Related recommendations:

php object-oriented final keyword usage and examples

The above is the detailed content of How to use the final keyword in Guantu in PHP. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn