Home  >  Article  >  Backend Development  >  What are static methods and ordinary methods in php

What are static methods and ordinary methods in php

青灯夜游
青灯夜游Original
2020-09-28 14:31:382181browse

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,.... ){
//方法体。。。
}
}

Calling form:

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

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,.... ){
//方法体。。。
}
}

Calling form:

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

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!

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