当前位置:网站首页>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);
边栏推荐
- Aruba learning notes 06 wireless control AC basic configuration (CLI)
- Little dolphin "transformed" into a new intelligent scheduling engine, which can be explained in simple terms in the practical development and application of DDS
- Code random notes_ Linked list_ Turn over the linked list in groups of 25K
- 科目1-3
- 分类与回归的区别
- TCP triple handshake connection combing
- Linked list - 24. Exchange nodes in the linked list in pairs
- [assembly language practice] solve the unary quadratic equation ax2+bx+c=0 (including source code and process screenshots, parameters can be modified)
- Problems and abuse of protocol buffers
- web安全入门-开源防火墙Pfsense安装配置
猜你喜欢

Re6:读论文 LeSICiN: A Heterogeneous Graph-based Approach for Automatic Legal Statute Identification fro

dp最长公共子序列详细版本(LCS)

C#/VB. Net: convert word or EXCEL documents to text
![[don't bother with reinforcement learning] video notes (I) 3. Why use reinforcement learning?](/img/57/0ebff0839d2a2898472d3270fd13df.png)
[don't bother with reinforcement learning] video notes (I) 3. Why use reinforcement learning?

Gnuplot software learning notes

【我的创作一周年纪念日】爱情是需要被纪念的,创作也是

Tang Yudi opencv background modeling

Re6: reading paper licin: a heterogeneous graph based approach for automatic legal stat identification fro

Asyncdata cross domain error after nuxt route switching

力扣300-最长递增子序列——动态规划
随机推荐
Scarcity in Web3: how to become a winner in a decentralized world
链表——19. 删除链表的倒数第 N 个结点
财务数字化转型
We were tossed all night by a Kong performance bug
SQL 优化原则
JS locate Daquan to get the brother, parent and child elements of the node, including robot instances
Detailed sequence traversal of leetcode102 binary tree
详解LinkedList
Tiktok shop will add a new site, and the Singapore site will be launched on June 9
[don't bother to strengthen learning] video notes (II) 2. Write a small example of Q learning
Code random notes_ Linked list_ Turn over the linked list in groups of 25K
Replace the function of pow with two-dimensional array (solve the time overrun caused by POW)
[don't bother with intensive learning] video notes (III) 1. What is SARS?
(5) Cloud integrated gateway gateway +swagger documentation tool
【我的创作一周年纪念日】爱情是需要被纪念的,创作也是
Account 1-3
《动手学深度学习》(七) -- 边界框和锚框
分类与回归的区别
[the first anniversary of my creation] love needs to be commemorated, so does creation
Aruba learning notes 06 wireless control AC basic configuration (CLI)