What are static methods and ordinary methods in php

青灯夜游
Release: 2023-03-06 08:06:02
Original
2188 people have browsed it

In PHP, static methods are defined in a class and modified by the static keyword. They only belong to the class itself and are not methods of objects of this class; ordinary methods are defined in a class. , a method that can be called for all objects of this class.

What are static methods and ordinary methods in php

Recommended: "PHP Video Tutorial"

Ordinary method (instance method)

A method defined in a class can be called for all objects of this class. It can also be understood that all objects of this class have their own method;

Definition form:

class  类名{
function  方法名(形参1,形参2,.... ){
//方法体。。。
}
}
Copy after login

Calling form:

$对象名->方法名(实参1,实参2,....);
Copy after login

Static method

The method defined in a class only belongs to the class itself, not to the objects of this class .

Definition form:

class  类名{
static  function  方法名(形参1,形参2,.... ){
//方法体。。。
}
}
Copy after login

Calling form:

类名::方法名(实参1,实参2,....);
Copy after login

Example (comprehensive example of properties and methods)

What are static methods and ordinary methods in php

Related recommendations: php training

The above is the detailed content of What are static methods and ordinary methods 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!