当前位置:网站首页>如何在业务代码中使用 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;
边栏推荐
- Migrate Infones to stm32
- 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
- Anti shake and throttling are easy to understand
- Algorithm -- climbing stairs (kotlin)
- LTE CSFB process
- Remember an error in MySQL: the user specified as a definer ('mysql.infoschema '@' localhost ') does not exist
- 移植InfoNES到STM32
- [JVM] [Chapter 17] [garbage collector]
- YYGH-11-定时统计
- Jushan database appears again in the gold fair to jointly build a new era of digital economy
猜你喜欢
Rustdesk builds its own remote desktop relay server
H3C防火墙RBM+VRRP 组网配置
Migrate Infones to stm32
[Jiudu OJ 07] folding basket
P2802 go home
Yygh-11-timing statistics
Text classification still stays at Bert? The dual contrast learning framework is too strong
PDK工艺库安装-CSMC
B站刘二大人-线性回归及梯度下降
巨杉数据库再次亮相金交会,共建数字经济新时代
随机推荐
什么是独立IP,独立IP主机怎么样?
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
PDK工藝庫安裝-CSMC
Algorithm -- climbing stairs (kotlin)
【论文代码】SML部分代码阅读
SequoiaDB湖仓一体分布式数据库2022.6月刊
What preparations should be made for website server migration?
P2802 go home
Promise summary
ARTS Week 25
Closure, decorator
The digital economy has broken through the waves. Is Ltd a Web3.0 website with independent rights and interests?
网络协议模型
Database: ODBC remote access SQL Server2008 in oracel
How to get list length
Cannot build artifact 'test Web: War expanded' because it is included into a circular depend solution
Analysis report on development trends and investment planning of China's methanol industry from 2022 to 2028
【课程笔记】编译原理
JS array list actual use summary
[imgui] unity MenuItem shortcut key