PHP中的戏法方法

WBOY
Release: 2016-06-13 12:10:03
Original
801 people have browsed it

PHP中的魔术方法
常用的魔术方法有:

__construct(), __destruct(), __call(), __callStatic(), __get(), __set(), __isset(), __unset(), __sleep(), __wakeup(), __toString(), __invoke(), __set_state(), __clone() 和 __debugInfo()

自己对魔术方法的一些理解:
1、php对象在某些特定操作的时候,会调用特定的魔术方法。如构造对象时调用__construct()。
2、在面向对象编程时,__call()会有比较大的用处。对于__call()的解释:在对象中调用一个不可访问方法时,__call() 会被调用。一些框架中,通过__call()将路由信息和对象方法联系到一起,比如CI框架。
3、关于__clone()的用途:当复制完成时,如果定义了 __clone() 方法,则新创建的对象(复制生成的对象)中的 __clone() 方法会被调用,可用于修改属性的值(如果有必要的话)。



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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!