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

不言
Release: 2023-04-03 18:02:01
Original
1789 people have browsed it

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();
Copy after login

Abstract class

abstract class Person{    
abstract function say();
}
Copy after login

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

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!

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!