doudun3910 2011-12-16 14:14
浏览 101
已采纳

将参数数组传递给对象构造函数

How can I call a object constructor passing an array of parameters so that having:

$array = array($param1, $param2);

I'll be able to call

$abc = new Abc($param1, $param2);

considering that I don't know how many parameters could be set in the array. Is there something like call_object('Abc', array($param1, $param2))?

  • 写回答

4条回答 默认 最新

  • douyao7390 2011-12-16 14:17
    关注

    The best way is to use an array or object that stores the arguments and you just pass that array/object

    Another way would be using Reflection ( http://de2.php.net/Reflection ) using newInstanceArgs ( http://de2.php.net/manual/de/reflectionclass.newinstanceargs.php )

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?