当前位置:网站首页>如何在业务代码中使用 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;
边栏推荐
- Li Chuang EDA learning notes 12: common PCB board layout constraint principles
- B站刘二大人-数据集及数据加载 Lecture 8
- Installation de la Bibliothèque de processus PDK - csmc
- 清除浮动的方式
- Closure, decorator
- Auto. JS learning notes 17: basic listening events and UI simple click event operations
- [Jiudu OJ 08] simple search x
- 实践分享:如何安全快速地从 Centos迁移到openEuler
- Practice sharing: how to safely and quickly migrate from CentOS to openeuler
- JS array list actual use summary
猜你喜欢

Remember an error in MySQL: the user specified as a definer ('mysql.infoschema '@' localhost ') does not exist

How can large websites choose better virtual machine service providers?

SequoiaDB湖仓一体分布式数据库2022.6月刊

Game push image / table /cv/nlp, multi-threaded start

Baidu online AI competition - image processing challenge: the 8th program of handwriting erasure

初识数据库

What is independent IP and how about independent IP host?

Station B, Master Liu Er - back propagation

P2802 go home

Web服务连接器:Servlet
随机推荐
[force buckle]43 String multiplication
B站刘二大人-线性回归 Pytorch
continue和break的区别与用法
How to use PHP string query function
Auto. JS learning notes 17: basic listening events and UI simple click event operations
实践分享:如何安全快速地从 Centos迁移到openEuler
华为路由器忘记密码怎么恢复
MIT6.s081-2020 Lab2 System Calls
Summary of data sets in intrusion detection field
CoDeSys note 2: set coil and reset coil
Easy to understand IIC protocol explanation
Yunxiaoduo software internal test distribution test platform description document
查詢生產訂單中某個(些)工作中心對應的標准文本碼
什么是独立IP,独立IP主机怎么样?
Download, install and use NVM of node, and related use of node and NRM
Improve jpopup to realize dynamic control disable
Selective parameters in MATLAB functions
Report on the competition status and investment decision recommendations of Guangxi hospital industry in China from 2022 to 2028
Clear floating mode
28io stream, byte output stream writes multiple bytes