Detailed explanation of the usage of final keyword in php

墨辰丷
Release: 2023-03-28 11:40:02
Original
2417 people have browsed it

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{
   .......
}
Copy after login

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(){
    ......
  }
}
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!