当前位置:网站首页>PHP Basics - PHP magic method
PHP Basics - PHP magic method
2022-07-24 09:24:00 【Chon.Wang】
PHP 13 There are three common magic methods :
__construct、__destruct、__call or __callStatic、__get、__set、__isset、__unset、__toString、__clone、__autoload、__invoke、__sleep、__wakeup
1. __construct Construction method
__constructConstruction method , When a class is instantiated to create an object , Will call the constructor .
2. __destruct destructor
__destructdestructor , When an object is destroyed or loses a reference to the object , Would call destructor .
3. __call or __callStatic
When calling an undefined or unauthorized member method , Would call
__callMethod .( When calling an undefined or unauthorized member method in a static method , It will call__callStaticMethod .)If this class cannot find the called member method , Will find it in the parent class .
If this class cannot be found
__callMethod , Will find it in the parent class .
4. __get
When calling an undefined or non-public member property , Would call
__getMethod .
5. __set
When assigning a value to an undefined or non-public member attribute , Would call
__setMethod .
6. __isset
When called on an undefined or non-public member attribute
issetFunction time , Would call__issetMethod .
7. __unset
When called on an undefined or non-public member attribute
unsetFunction time , Would call__unsetMethod .
8. __toString
When printing out an object , Automatically called
__toStringMethod . example :echo Object name.
9. __clone
When cloning an object , Automatically called
__cloneMethod . example :$clone_obj = clone Object name ;
10. __autoload
When instantiating an undefined class, it will automatically call
__autoloadTo load class files .
11. __invoke
When trying to call an object as a function , Automatically called
__invokeMethod .
12. __sleep
serialize()Function will check whether there is__sleepMethod , If there is , Execute first__sleepMethod , Re execution Serialization operation .<?php class User { public function __sleep(){ // } } $obj = new User(); serialize($obj);
13. __wakeup
unserialize()Function will check whether there is__wakeupMethod , If there is , Execute first__wakeupMethod , Re execution Deserialization operation .<?php class User { public function __wakeup(){ // } } $obj = new User(); unserialize($obj);
边栏推荐
- js定位大全获取节点的兄弟,父级,子级元素含robot实例
- (5) Cloud integrated gateway gateway +swagger documentation tool
- Linked list - 24. Exchange nodes in the linked list in pairs
- 来阿里一年后我迎来了第一次工作变动....
- JS locate Daquan to get the brother, parent and child elements of the node, including robot instances
- How should tiktok shop cooperate with live broadcast in the background?
- LeetCode刷题系列-- 174. 地下城游戏
- How to judge and analyze NFT market briefly through NFT go?
- Aruba learning notes 06 wireless control AC basic configuration (CLI)
- [Luogu p5829] [template] mismatch tree (string) (KMP)
猜你喜欢

Problems and abuse of protocol buffers

One year after I came to Ali, I ushered in my first job change

Linked list - 19. Delete the penultimate node of the linked list

Li Kou 300 longest increasing subsequence dynamic programming

数据中台:始于阿里,兴于DaaS

Asyncdata cross domain error after nuxt route switching

Leetcode94-二叉树的中序遍历详解

Nuxt 路由切换后 asyncData 跨域报错
![[assembly language practice] solve the unary quadratic equation ax2+bx+c=0 (including source code and process screenshots, parameters can be modified)](/img/5e/782e5c33accc455994aae044970431.png)
[assembly language practice] solve the unary quadratic equation ax2+bx+c=0 (including source code and process screenshots, parameters can be modified)

Android system security - 5.3-apk V2 signature introduction
随机推荐
Cess test online line! The first decentralized storage network to provide multiple application scenarios
【汇编语言实战】(二)、编写一程序计算表达式w=v-(x+y+z-51)的值(含代码、过程截图)
Replace the function of pow with two-dimensional array (solve the time overrun caused by POW)
MySQL基础篇(一)-- SQL基础
Tiktok shop platform will take disciplinary measures against sellers who violate rules and policies
Nuggets manufacturing industry, digital commerce cloud supply chain collaborative management system to achieve full chain intelligent management and control
CUDA day 2: GPU core and Sm core components [easy to understand]
JUC powerful auxiliary class
Practice 4-6 number guessing game (15 points)
Tiktok shop will add a new site, and the Singapore site will be launched on June 9
【汇编语言实战】一元二次方程ax2+bx+c=0求解(含源码与过程截屏,可修改参数)
Definition and initialization of cv:: mat
华为无线设备安全策略配置命令
云原生(十二) | Kubernetes篇之Kubernetes基础入门
Account 1-3
Map processing background management menu data
力扣300-最长递增子序列——动态规划
Why is TCP a triple handshake
UE5影视动画渲染MRQ分层学习笔记
Code random notes_ Linked list_ Turn over the linked list in groups of 25K