• <legend id='KiPTC'><style id='KiPTC'><dir id='KiPTC'><q id='KiPTC'></q></dir></style></legend>

  • <small id='KiPTC'></small><noframes id='KiPTC'>

    <tfoot id='KiPTC'></tfoot>
      • <bdo id='KiPTC'></bdo><ul id='KiPTC'></ul>

      1. <i id='KiPTC'><tr id='KiPTC'><dt id='KiPTC'><q id='KiPTC'><span id='KiPTC'><b id='KiPTC'><form id='KiPTC'><ins id='KiPTC'></ins><ul id='KiPTC'></ul><sub id='KiPTC'></sub></form><legend id='KiPTC'></legend><bdo id='KiPTC'><pre id='KiPTC'><center id='KiPTC'></center></pre></bdo></b><th id='KiPTC'></th></span></q></dt></tr></i><div id='KiPTC'><tfoot id='KiPTC'></tfoot><dl id='KiPTC'><fieldset id='KiPTC'></fieldset></dl></div>
      2. PHP 从构造函数获取返回值

        时间:2023-06-22

        <tfoot id='CaKuZ'></tfoot>
            <tbody id='CaKuZ'></tbody>

              <small id='CaKuZ'></small><noframes id='CaKuZ'>

              <legend id='CaKuZ'><style id='CaKuZ'><dir id='CaKuZ'><q id='CaKuZ'></q></dir></style></legend>
                <bdo id='CaKuZ'></bdo><ul id='CaKuZ'></ul>

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

                  问题描述

                  我很困惑,我有一个带有构造函数的 PHP 类:

                  I am confused, I have a PHP class with a constructor:

                  class Test {
                     public function __construct() {
                        return "some text";
                     }
                  }
                  

                  然后我实例化一个对象:

                  Then I instanciate an object:

                  $t = new Test();
                  

                  我希望 $t 的内容是一些文本":

                  I would expect the contents of $t to be "some text":

                  print_r($t);
                  

                  但它是:

                  Test Object
                  (
                  )
                  

                  如何从构造函数中获取返回值"some text"?

                  How do I get the returned value "some text" from the constructor?

                  推荐答案

                  你不能从构造函数return任何东西.new 关键字总是会产生一个新的对象,不管你从构造函数中return 什么.

                  You cannot return anything from a constructor. The new keyword will always result in a new object, it does not matter what you return from the constructor.

                  这篇关于PHP 从构造函数获取返回值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:为什么 PHP 允许“不兼容"构造函数? 下一篇:具有相同标识符的多个 HTTP GET 参数

                  相关文章

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

                  <legend id='EUv4W'><style id='EUv4W'><dir id='EUv4W'><q id='EUv4W'></q></dir></style></legend>

                    <small id='EUv4W'></small><noframes id='EUv4W'>

                    1. <tfoot id='EUv4W'></tfoot>