call_user_func()详解
来源:互联网 发布:java int 0x 编辑:程序博客网 时间:2024/06/05 22:48
先来看解释 :
(PHP 4, PHP 5, PHP 7)
call_user_func — 把第一个参数作为回调函数调用
通过函数的方式回调<?php function barber($type){echo "you wanted a $type haircut, no problem\n";}call_user_func('barber','mushroom'); ?>
返回内容如下:
you wanted a mushroom haircut, no problem
通过类名、对象的方式回调
<?php /** * 用call_user_func()来调用一个类里面的方法 */class myclass{static function say_hello(){echo "hello!\n";}}$classname = "myclass";//通过数组键值的方式,对类名进行回调,回调类名里面的,say_hello方法call_user_func(array($classname,'say_hello'));//通过类名直接调用静态方法call_user_func($classname .'::say_hello'); // As of 5.2.3// $myobject = new myclass();//通过对象的方式回调$myobject = new myclass();call_user_func(array($myobject, 'say_hello')); ?>
通过$this关键字进行对类的回调,以下源码出自thinkphp5 controller.php 200行
call_user_func([$this, $method]);
阅读全文
0 0
- call_user_func()详解
- PHP函数详解:call_user_func()使用方法
- PHP函数详解:call_user_func()使用方法
- PHP函数详解:call_user_func()使用方法
- PHP函数详解:call_user_func()使用方法
- call_user_func()
- call_user_func
- call_user_func
- call_user_func
- call_user_func
- call_user_func
- call_user_func
- call_user_func
- call_user_func()
- php函数call_user_func和call_user_func_array详解
- php函数call_user_func和call_user_func_array详解
- php函数call_user_func和call_user_func_array详解
- php函数call_user_func和call_user_func_array详解
- 异常
- Linux web服务的基本配置(httpd)
- 操作Excel文件
- js中获取时间new Date()详细介绍
- 正则表达式匹配所有不包含 css 的 html 标签
- call_user_func()详解
- nginx服务器的事件驱动模型
- vim youcompeteme 插件安装
- ThinkPHP 验证码错误
- 关于Java中常用的集合类总结
- 浅谈Java中的hashCode和HashMap
- MySQL中的复制全表到新表
- andorid TextView(3)-使用HTML标签
- IOS Swift3.1 打印视图生命周期