What is the difference between php functions and methods?

青灯夜游
Release: 2023-02-27 12:04:01
Original
6888 people have browsed it

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template