Home > Backend Development > PHP Problem > What is the concept of magic method in php

What is the concept of magic method in php

王林
Release: 2023-03-11 09:46:01
Original
2915 people have browsed it

The concept of magic methods in php is methods starting with two underscores, such as __construct(), __destruct(), __call(), __callStatic(), etc.

What is the concept of magic method in php

The operating environment of this article: windows10 system, php 7.3, thinkpad t480 computer.

Magic methods refer to methods starting with two underscores in PHP, __construct(), __destruct (), __call(), __callStatic(),__get(), __set(), __isset(), __unset (), __sleep(), __wakeup(), __toString(), __set_state,() __clone() __autoload(), etc.

If you want PHP to call these magic methods, you must first define them in the class, otherwise PHP will not execute uncreated magic methods.

Note: PHP reserves all class methods starting with __ (two underscores) as magic methods. Therefore, when defining class methods, except for the above magic methods, it is recommended not to prefix them with __.

Free learning video recommendation: Programming video

The above is the detailed content of What is the concept of magic method in php. 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