<bdo id='Pw8dX'></bdo><ul id='Pw8dX'></ul>
<legend id='Pw8dX'><style id='Pw8dX'><dir id='Pw8dX'><q id='Pw8dX'></q></dir></style></legend>
  1. <i id='Pw8dX'><tr id='Pw8dX'><dt id='Pw8dX'><q id='Pw8dX'><span id='Pw8dX'><b id='Pw8dX'><form id='Pw8dX'><ins id='Pw8dX'></ins><ul id='Pw8dX'></ul><sub id='Pw8dX'></sub></form><legend id='Pw8dX'></legend><bdo id='Pw8dX'><pre id='Pw8dX'><center id='Pw8dX'></center></pre></bdo></b><th id='Pw8dX'></th></span></q></dt></tr></i><div id='Pw8dX'><tfoot id='Pw8dX'></tfoot><dl id='Pw8dX'><fieldset id='Pw8dX'></fieldset></dl></div>

      <tfoot id='Pw8dX'></tfoot>
    1. <small id='Pw8dX'></small><noframes id='Pw8dX'>

    2. 如何在 PHP 中使用 call_user_func_array 调用构造函数

      How to call the constructor with call_user_func_array in PHP(如何在 PHP 中使用 call_user_func_array 调用构造函数)
      <legend id='7jVTh'><style id='7jVTh'><dir id='7jVTh'><q id='7jVTh'></q></dir></style></legend>

          <tbody id='7jVTh'></tbody>
            • <bdo id='7jVTh'></bdo><ul id='7jVTh'></ul>

              • <tfoot id='7jVTh'></tfoot>

                <small id='7jVTh'></small><noframes id='7jVTh'>

                <i id='7jVTh'><tr id='7jVTh'><dt id='7jVTh'><q id='7jVTh'><span id='7jVTh'><b id='7jVTh'><form id='7jVTh'><ins id='7jVTh'></ins><ul id='7jVTh'></ul><sub id='7jVTh'></sub></form><legend id='7jVTh'></legend><bdo id='7jVTh'><pre id='7jVTh'><center id='7jVTh'></center></pre></bdo></b><th id='7jVTh'></th></span></q></dt></tr></i><div id='7jVTh'><tfoot id='7jVTh'></tfoot><dl id='7jVTh'><fieldset id='7jVTh'></fieldset></dl></div>
                本文介绍了如何在 PHP 中使用 call_user_func_array 调用构造函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                如何使用 call_user_func_array 调用类的构造函数

                How could I call the constructor of a class with call_user_func_array

                这是不可能的:

                $obj = new $class();
                call_user_func_array(array($obj, '__construct'), $args); 
                

                因为如果构造函数有参数,new 就会失败.

                because if the constructor has parameters, the new will fail.

                约束:我不能控制必须实例化的类,也不能修改它们.

                Constraint : I do not control the classes that I have to instantiate, nor can I modify them.

                别问我为什么要做这个疯狂的事情,这是一个疯狂的测试.

                Don't ask me why I want to do this crazy thing, this is a crazy test.

                推荐答案

                你可以使用 reflection 像:>

                You can use reflection like:

                $reflect  = new ReflectionClass($class);
                $instance = $reflect->newInstanceArgs($args);
                

                <小时>

                从 PHP 5.6.0 开始,... 运算符也可用于此目的.


                As of PHP 5.6.0, the ... operator can also be used for this purpose.

                $instance = new $class(...$args);
                

                <小时>

                if(version_compare(PHP_VERSION, '5.6.0', '>=')){
                    $instance = new $class(...$args);
                } else {
                    $reflect  = new ReflectionClass($class);
                    $instance = $reflect->newInstanceArgs($args);
                }
                

                这篇关于如何在 PHP 中使用 call_user_func_array 调用构造函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
                PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
                mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
                Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
                Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
                Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)

                1. <small id='Zo7BY'></small><noframes id='Zo7BY'>

                2. <legend id='Zo7BY'><style id='Zo7BY'><dir id='Zo7BY'><q id='Zo7BY'></q></dir></style></legend>

                    <tbody id='Zo7BY'></tbody>
                        <bdo id='Zo7BY'></bdo><ul id='Zo7BY'></ul>

                      • <tfoot id='Zo7BY'></tfoot>
                        • <i id='Zo7BY'><tr id='Zo7BY'><dt id='Zo7BY'><q id='Zo7BY'><span id='Zo7BY'><b id='Zo7BY'><form id='Zo7BY'><ins id='Zo7BY'></ins><ul id='Zo7BY'></ul><sub id='Zo7BY'></sub></form><legend id='Zo7BY'></legend><bdo id='Zo7BY'><pre id='Zo7BY'><center id='Zo7BY'></center></pre></bdo></b><th id='Zo7BY'></th></span></q></dt></tr></i><div id='Zo7BY'><tfoot id='Zo7BY'></tfoot><dl id='Zo7BY'><fieldset id='Zo7BY'></fieldset></dl></div>