Home  >  Article  >  Backend Development  >  A brief introduction to abstract methods, abstract classes and interfaces in PHP

A brief introduction to abstract methods, abstract classes and interfaces in PHP

不言
不言Original
2018-08-10 11:10:151841browse

This article brings you a brief introduction to abstract methods, abstract classes and interfaces in PHP. It has certain reference value. Friends in need can refer to it. I hope it will be useful to you. Helps.

Abstract method

abstract function say();

Abstract class

abstract class Person{    
abstract function say();
}

1. Abstract classes cannot be instantiated

2 . Abstract classes can have abstract methods

3. Subclasses must implement abstract methods

Interface

1. All methods in the interface It is an abstract method

2. The interface attribute must be a constant

3. It must be public

4.Interface declaration

interface Demo{    
const NAME=’ngyhd’;    
function test();}

Related recommendations:

Code examples of non-forwarding calls and forwarding calls in php

How to implement the page jump function in PHP? (Function label example)

The above is the detailed content of A brief introduction to abstract methods, abstract classes and interfaces 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