当前位置:网站首页>如何在业务代码中使用 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;
边栏推荐
- Embedded interview questions (IV. common algorithms)
- Station B, Master Liu Er - back propagation
- LTE CSFB process
- 关于 PHP 启动 MongoDb 找不到指定模块问题
- [experience] install Visio on win11
- Self built DNS server, the client opens the web page slowly, the solution
- 通讯录管理系统链表实现
- 清除浮动的方式
- 【SQL server速成之路】——身份验证及建立和管理用户账户
- Hongliao Technology: how to quickly improve Tiktok store
猜你喜欢

B站刘二大人-Softmx分类器及MNIST实现-Lecture 9

YYGH-11-定时统计

Web服务连接器:Servlet

华为路由器如何配置静态路由

Redis消息队列

H3C V7版本交换机配置IRF

Jushan database appears again in the gold fair to jointly build a new era of digital economy

A master in the field of software architecture -- Reading Notes of the beauty of Architecture

Self built DNS server, the client opens the web page slowly, the solution

What is independent IP and how about independent IP host?
随机推荐
01. Project introduction of blog development project
实践分享:如何安全快速地从 Centos迁移到openEuler
Migrate Infones to stm32
Redis message queue
H3C S5820V2_5830V2交换机IRF2堆叠后升级方法
Codeless June event 2022 codeless Explorer conference will be held soon; AI enhanced codeless tool launched
Go language -- language constants
LeetCode_字符串反转_简单_557. 反转字符串中的单词 III
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
[machine learning notes] univariate linear regression principle, formula and code implementation
PDK工艺库安装-CSMC
Garbage collector with serial, throughput priority and response time priority
清除浮动的方式
应用安全系列之三十七:日志注入
大型网站如何选择比较好的云主机服务商?
RustDesk 搭建一个自己的远程桌面中继服务器
c语言——冒泡排序
养了只小猫咪
Improve jpopup to realize dynamic control disable
Yunxiaoduo software internal test distribution test platform description document