当前位置:网站首页>如何在业务代码中使用 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;
边栏推荐
- AUTOSAR从入门到精通番外篇(十)-嵌入式S19文件解析
- Classes and objects (I) detailed explanation of this pointer
- [happy Spring Festival] if you feel happy, dance
- [machine learning notes] univariate linear regression principle, formula and code implementation
- Clear floating mode
- [string] palindrome string of codeup
- Memory and stack related concepts
- 查詢生產訂單中某個(些)工作中心對應的標准文本碼
- Closure, decorator
- [imgui] unity MenuItem shortcut key
猜你喜欢

Node 之 nvm 下载、安装、使用,以及node 、nrm 的相关使用

Download, install and use NVM of node, and related use of node and NRM

大型网站如何选择比较好的云主机服务商?
![[Tang Laoshi] C -- encapsulation: classes and objects](/img/4e/30d2d4652ea2d4cd5fa7cbbb795863.jpg)
[Tang Laoshi] C -- encapsulation: classes and objects

B站刘二大人-线性回归及梯度下降

H3C V7版本交换机配置IRF

What preparations should be made for website server migration?
![[JVM] [Chapter 17] [garbage collector]](/img/f4/e6ff0e3edccf23399ec12b7913749a.jpg)
[JVM] [Chapter 17] [garbage collector]

网络协议模型

Self built DNS server, the client opens the web page slowly, the solution
随机推荐
PDK工艺库安装-CSMC
[Jiudu OJ 08] simple search x
Processes and threads
PDK工藝庫安裝-CSMC
Station B Liu Erden linear regression pytoch
Some easy-to-use tools make your essay style more elegant
嵌入式面试题(一:进程与线程)
Is it difficult for an information system project manager?
关于 PHP 启动 MongoDb 找不到指定模块问题
Analysis report on development trends and investment planning of China's methanol industry from 2022 to 2028
[force buckle]43 String multiplication
AUTOSAR from getting started to becoming proficient (10) - embedded S19 file analysis
How to download GB files from Google cloud hard disk
Remember an error in MySQL: the user specified as a definer ('mysql.infoschema '@' localhost ') does not exist
Mysql database master-slave cluster construction
Practice sharing: how to safely and quickly migrate from CentOS to openeuler
PDK process library installation -csmc
Implementation of linked list in address book management system
[Baiwen smart home] first day of the course_ Learn Embedded and understand the development mode of bare metal and RTOS
ArcGIS application foundation 4 thematic map making