Home > Backend Development > PHP Problem > The difference between php functions and methods

The difference between php functions and methods

(*-*)浩
Release: 2023-02-26 18:50:02
Original
4064 people have browsed it

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!

Related labels:
php
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template