我爱占星网 我爱占星网
首页
编程
java
php
前端
首页 编程 java php 前端

php:来自“ClassName”的新对象和args数组

I have string containing classname and an array of args.
$classname($args) works, but in this case I have only 1 argument in constructor
Anyone know, how to do this with args expanded?

$reflection = new ReflectionClass($classname);
$object = $reflection->newInstanceArgs($args);

http://php.net/reflection

Haha I just asked this question: PHP passing a class as a reference?

And you can't expand the $args. You could try passing $args[0], $args[1] etc.

近期文章

  • 为什么迁移数据库不能在laravel中工作?
  • php.ini不会在public_html目录之外工作
  • 我们如何在隐私浏览模式下打开链接
  • MAGENTO:如何从文件中更新category_ids?
  • 无法在Google Plus JSON中访问附件数据
  • 在Magento中处理模型常量的正确方法
  • WordPress主题中的.css引用在哪里?
  • 通过多维数组值获取数组部分
  • Symfony2在组件中找不到jquery.js文件
  • 从foreach类函数返回单个数组
  • 超薄框架 - 无法解释带点的路线
  • PHP Mailer消息未正确通过
  • 获取Twitter提及未经过身份验证的用户
  • 是否可以将HHVM字节码存储为文件?
  • DataTransformer中的reverseTransform不起作用
  • 使用复选框和PHP更新MySQL数据库
  • 统计页面 - 逐个加载每个统计信息<div>
  • 使用PHP和MySQL的'字段列表'中的未知列''
  • 通过php将多个表行插入mysql
  • 刀片模板中的foreach无法正常工作

Copyright ©2022 我爱占星 All Rights Reserved.

浙ICP备2022030071号-1

部分图文来自网络,如有侵犯您的版权,请告诉我们删除

友情链接:代码精华