当前位置:网站首页>如何在业务代码中使用 ThinkPHP5.1 封装的容器内反射方法
如何在业务代码中使用 ThinkPHP5.1 封装的容器内反射方法
2022-07-06 05:47:00 【北桥苏】
invokeClass
用法:可以不传命名空间实例化 (通过反射实例化)
$obj = Container::getInstance()->invokeClass(InvokerTest::class);
var_dump($obj->invokerNews());die;
-----------------------------------------------------------------------
invokeMethod
用法:传入带命名空间的类和对应方法,实例化后调用该方法
$methods = Container::getInstance()->invokeMethod(["app\common\service\InvokerTest", "invokerNews"]);
var_dump($methods);die;
-----------------------------------------------------------------------
invokeFunction
用法:可以执行自定义的函数和闭包,参数以数组形式传递
$functions = Container::getInstance()->invokeFunction(function ($name) {
return "hello {$name}";
}, ["beiqiaosu"]);
var_dump($functions);die;
$functions = Container::getInstance()->invokeFunction("procmsg", ["12312", "heillo"]);
var_dump($functions);die;
-----------------------------------------------------------------------
invoke
用法:invokeFunction 和 invokeMethod 结合体
$invoke = Container::getInstance()->invoke(["app\common\service\InvokerTest", "invokerNews"]);
var_dump($invoke);die;
边栏推荐
- Game push image / table /cv/nlp, multi-threaded start
- Zoom through the mouse wheel
- 查詢生產訂單中某個(些)工作中心對應的標准文本碼
- 进程和线程
- H3C V7版本交换机配置IRF
- 查询生产订单中某个(些)工作中心对应的标准文本码
- LeetCode_ String inversion_ Simple_ 557. Reverse word III in string
- 巨杉数据库再次亮相金交会,共建数字经济新时代
- [force buckle]43 String multiplication
- Embedded interview questions (IV. common algorithms)
猜你喜欢
[Baiwen smart home] first day of the course_ Learn Embedded and understand the development mode of bare metal and RTOS
华为路由器如何配置静态路由
Construction of yolox based on paste framework
Application Security Series 37: log injection
巨杉数据库再次亮相金交会,共建数字经济新时代
How to download GB files from Google cloud hard disk
移植InfoNES到STM32
[force buckle]43 String multiplication
大型网站如何选择比较好的云主机服务商?
Installation de la Bibliothèque de processus PDK - csmc
随机推荐
Note the various data set acquisition methods of jvxetable
LeetCode_字符串反转_简单_557. 反转字符串中的单词 III
Yygh-11-timing statistics
【论文代码】SML部分代码阅读
Summary of data sets in intrusion detection field
Report on market depth analysis and future trend prediction of China's arsenic trioxide industry from 2022 to 2028
05. Security of blog project
嵌入式面试题(一:进程与线程)
Sequoiadb Lake warehouse integrated distributed database, June 2022 issue
A master in the field of software architecture -- Reading Notes of the beauty of Architecture
B站刘二大人-反向传播
【SQL server速成之路】——身份验证及建立和管理用户账户
RustDesk 搭建一个自己的远程桌面中继服务器
[Jiudu OJ 08] simple search x
59. Spiral matrix
Closure, decorator
Embedded interview questions (I: process and thread)
Auto.js学习笔记17:基础监听事件和UI简单的点击事件操作
Application Security Series 37: log injection
Game push image / table /cv/nlp, multi-threaded start