Home  >  Article  >  Backend Development  >  What are the class modifiers in PHP?

What are the class modifiers in PHP?

(*-*)浩
(*-*)浩Original
2019-10-09 11:02:453679browse

Class modifier

What are the class modifiers in PHP?

## The class modified by abstract is an abstract class, If a class contains an abstract method, then the class is an abstract class (of course there is no abstract method in a class, we can also define this class as an abstract class), then what is an abstract method? An abstract method is a method without a method body (no Braces and the contents inside), abstract methods are also modified in front of them. (Recommended learning: PHP Video Tutorial)

The abstract class itself cannot be instantiated, only one class inherits it and overrides all its abstract methods, so that we can instantiate it The subclass of

abstract class My{
    abstract function say();
}
//
abstract class My{
     function say(){
        echo 'hello';
    }
}

interface modified class is interface. Interface is somewhat similar to abstract class, but their difference is that all methods of interface are abstract methods. In front of the abstract method of interface Without abstract modification, member properties must be constants.

Interface references are different from class inheritance keyword extends. Inheritance can only be single, while interfaces can use the keyword implements to have multiple references separated by commas.


interface demo {
const NAME = "常量对象属性";
function fun1();
function fun2(); //抽象方法。 
}
class MyPc extends Root implements demo , demo2 , demo3 {
...
}

The class modified by final is a terminal class and cannot be inherited.

The above is the detailed content of What are the class modifiers 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