当前位置:网站首页>如何在业务代码中使用 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;
边栏推荐
- First knowledge database
- Processes and threads
- 查询生产订单中某个(些)工作中心对应的标准文本码
- 嵌入式面试题(四、常见算法)
- Auto.js学习笔记17:基础监听事件和UI简单的点击事件操作
- Game push: image / table /cv/nlp, multi-threaded start!
- How to download GB files from Google cloud hard disk
- 初识数据库
- Market development prospect and investment risk assessment report of China's humidity sensor industry from 2022 to 2028
- B站刘二大人-线性回归及梯度下降
猜你喜欢
High quality coding tool clion
28io stream, byte output stream writes multiple bytes
The digital economy has broken through the waves. Is Ltd a Web3.0 website with independent rights and interests?
【课程笔记】编译原理
A master in the field of software architecture -- Reading Notes of the beauty of Architecture
continue和break的区别与用法
类和对象(一)this指针详解
【论文阅读】NFlowJS:基于鲁棒学习的合成负数据密集异常检测
Report on market depth analysis and future trend prediction of China's arsenic trioxide industry from 2022 to 2028
What is independent IP and how about independent IP host?
随机推荐
移植InfoNES到STM32
LeetCode_字符串反转_简单_557. 反转字符串中的单词 III
ARTS Week 25
Text classification still stays at Bert? The dual contrast learning framework is too strong
Download, install and use NVM of node, and related use of node and NRM
Node 之 nvm 下载、安装、使用,以及node 、nrm 的相关使用
【SQL server速成之路】——身份验证及建立和管理用户账户
通讯录管理系统链表实现
华为路由器如何配置静态路由
P2802 回家
Clear floating mode
CoDeSys note 2: set coil and reset coil
wib3.0 跨越,在跨越(ง •̀_•́)ง
[force buckle]43 String multiplication
Quantitative description of ANC noise reduction
How to use PHP string query function
Cannot build artifact 'test Web: War expanded' because it is included into a circular depend solution
初识数据库
B站刘二大人-Softmx分类器及MNIST实现-Lecture 9
The usage and difference between strlen and sizeof