How to use the final keyword in Guantu in PHP

小云云
Release: 2023-03-22 17:12:01
Original
1343 people have browsed it

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

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

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!

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!