码迷,mamicode.com
首页 > Web开发 > 详细

PHP的魔术方法(简介)

时间:2015-05-02 19:24:46      阅读:136      评论:0      收藏:0      [点我收藏+]

标签:

public void _set(string $name,mixed $value)

public mixed _get(string $name)

public bool _isset(string $name)

public void _unset(string $name)

public mixed _call(string $name,array $arguments)

这些方法的作用如下:

_set(string $name,mixed $value):在对象给未定义或者不可见的属性赋值时被调用,参数name即为需要赋值的属性,value即为需要为属性赋的值。

_get(string $name):在对象访问未定义或者不可见的属性时被调用,参数name即为需要访问的属性名。

_isset(string $name):对未定义或者不可见的属性使用isset()时被调用,参数name即为属性名。

_unset(string $name):对未定义或者不可见的属性使用unset()时被调用,参数name即为属性名。

_call(string $name,array $arguments):在对象调用未定义或不可见的方法时被调用,参数name即为方法名,参数arguments为要传递给方法的参数组成的数组。

注意:这些模式方法的作用就是拦截到访问不存在的对象成员的操作,然后对其做相应的响应,并且这些方法都必须使用public修饰。

 

PHP的魔术方法(简介)

标签:

原文地址:http://www.cnblogs.com/ljfpoison/p/4472293.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!