Home  >  Article  >  Backend Development  >  What is the difference between methods and functions in php?

What is the difference between methods and functions in php?

WBOY
WBOYOriginal
2016-09-24 09:15:112150browse

I always thought it was the same thing, but I didn’t know it was the same thing until I read the thinkphp documentation, which contains the specifications of functions and methods. . . Asking for advice

Reply content:

I always thought it was the same thing, but I didn’t know it was the same thing until I read the thinkphp documentation, which contains the specifications of functions and methods. . . Asking for advice

Methods are "functions" in a class and can only be called through objects.
Specially, static methods of a class can be called directly through the class name.
Usually speaking, functions should be functions in the global scope. After being introduced, they can be Call directly from anywhere.

Do you think class methods are more fluent, or class functions are more fluent?

A simple distinction is:
Function exists alone, that is, it is defined in the process-oriented part.
Methods depend on the existence of classes, which are defined in object-oriented.

Function, you can think of it as the implementation of an algorithm.
method can be used as an implementation of business logic.

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
Previous article:Remote redis queue?Next article:Remote redis queue?