Home > Article > Backend Development > What is the difference between php functions and methods?
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.
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!