【问题标题】:How can I call a class with variables from array php? [duplicate]如何使用数组 php 中的变量调用类? [复制]
【发布时间】:2012-04-20 17:05:32
【问题描述】:

我想要这样的东西,但从这样的数组动态:

$array = array("first","second","third");

所以类会这样调用:

$class = new class("first","second","third");

【问题讨论】:

    标签: php arrays class


    【解决方案1】:

    你可以使用反射:

    $refClass = new ReflectionClass('SomeClass');
    $instance = $refClass->newInstanceArgs($args);
    

    【讨论】:

    • 表示第一次不反射(call_user_func)
    猜你喜欢
    • 1970-01-01
    • 2020-08-01
    • 1970-01-01
    • 2011-12-21
    • 2017-04-12
    • 2013-05-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多