Home >Backend Development >PHP Problem >The difference between php functions and methods
The difference between php functions and methods
#I always thought they were the same thing, until I read the thinkphp documentation, there are functions and methods Standard, only to know that it is not the same thing.
Methods are "functions" in a class and can only be called through objects (recommended learning: PHP video tutorial)
Specially, static methods of a class can be called through the class name directly.
The functions usually mentioned should be functions in the global scope, which can be called directly anywhere after being introduced.
The simple distinction is:
The 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
The above is the detailed content of The difference between php functions and methods. For more information, please follow other related articles on the PHP Chinese website!