Home  >  Article  >  Backend Development  >  Detailed explanation of the usage of final keyword in php

Detailed explanation of the usage of final keyword in php

墨辰丷
墨辰丷Original
2018-05-29 17:07:492363browse

This article mainly introduces the usage of the final keyword in php, and analyzes the function, usage and related precautions of the final keyword in the form of examples. Friends in need can refer to the following

The examples in this article describe Usage of final keyword in php. Share it with everyone 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 will occur hint. 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()

The above is the entire content of this article, I hope it will be helpful to everyone's study.


Related recommendations:

PHP interface implementation of drag-and-drop sorting function example

PHP Basic redis operations

PHPMethod to change the array key value

The above is the detailed content of Detailed explanation of the usage of final keyword 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