在php类中使用函数

好久没更新了,今天复习歪麦编写php框架的文章,看到几个函数,在类中使用时,当参数需要调用类的方法时,都用数组的方式传参。

1.  spl_autoload_register(array($this, 'loadClass'));

正常是这样用的 

spl_autoload_register('loadClass');

但是,当在类方法内使用,且参数也是方法时,就用上面spl_autoload_register(array($this, 'loadClass'))的方式调用,
array($this, 'loadClass'),表示本类的loadClass方法。

2.
array_map(array($this, 'stripSlashesDeep'), $value)
一样的道理,正常使用array_map时,传递一个函数名,现在传递的是类名,用的方法就是
array($this, 'stripSlashesDeep')这种办法。

3.
call_user_func_array(array($dispatch, $actionName), $param);
也是同样的道理。
原文地址:https://www.cnblogs.com/cblx/p/14464599.html