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