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

What is the difference between php functions and methods?

青灯夜游
青灯夜游Original
2019-10-19 11:08:056817browse

Before, I always thought that functions and methods were the same thing. It was not until I read the thinkphp documentation that there were specifications for functions and methods that I realized they were not the same thing.

What is the difference between php functions and methods?

Methods are "functions" in a class and can only be called through objects; in particular, static methods of a class can be called directly through the class name,

The functions usually mentioned should be functions in the global scope, which can be called directly anywhere after being introduced.

The difference between php functions and methods

Function exists alone, that is, it is defined in the process-oriented part.

The method depends on the existence of the class, which is defined in object-oriented.

Function, you can regard it as the implementation of an algorithm. The

method can be used as an implementation of business logic.

Class methods can set access permissions and need to be called through objects or classes; functions are public and can be used.

For more PHP related knowledge, please visit php中文网!

The above is the detailed content of What is the difference between php functions and methods?. 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