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

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

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

        如何解析“必须是字符串的实例,字符串给定&

        时间:2023-09-25
            <tbody id='PD8p0'></tbody>
        • <i id='PD8p0'><tr id='PD8p0'><dt id='PD8p0'><q id='PD8p0'><span id='PD8p0'><b id='PD8p0'><form id='PD8p0'><ins id='PD8p0'></ins><ul id='PD8p0'></ul><sub id='PD8p0'></sub></form><legend id='PD8p0'></legend><bdo id='PD8p0'><pre id='PD8p0'><center id='PD8p0'></center></pre></bdo></b><th id='PD8p0'></th></span></q></dt></tr></i><div id='PD8p0'><tfoot id='PD8p0'></tfoot><dl id='PD8p0'><fieldset id='PD8p0'></fieldset></dl></div>

          • <tfoot id='PD8p0'></tfoot>

            1. <legend id='PD8p0'><style id='PD8p0'><dir id='PD8p0'><q id='PD8p0'></q></dir></style></legend>

                <bdo id='PD8p0'></bdo><ul id='PD8p0'></ul>

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

                  本文介绍了如何解析“必须是字符串的实例,字符串给定"在 PHP 7 之前?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  这是我的代码:

                  function phpwtf(string $s) {
                      echo "$s
                  ";
                  }
                  phpwtf("Type hinting is da bomb");
                  

                  导致此错误的原因:

                  可捕获的致命错误:传递给 phpwtf() 的参数 1 必须是字符串的实例,给定的字符串

                  Catchable fatal error: Argument 1 passed to phpwtf() must be an instance of string, string given

                  看到 PHP 同时识别和拒绝所需的类型,这不仅仅是一点奥威尔式的.有五个灯,该死.

                  It's more than a little Orwellian to see PHP recognize and reject the desired type in the same breath. There are five lights, damn it.

                  PHP 中字符串类型提示的等价物是什么?对准确解释这里发生的事情的答案给予额外考虑.

                  What is the equivalent of type hinting for strings in PHP? Bonus consideration to the answer that explains exactly what is going on here.

                  推荐答案

                  PHP 7 之前的类型提示 只能用于强制对象和数组的类型.标量类型不是类型可提示的.在这种情况下,需要一个 string 类的对象,但你给它一个(标量)string.错误消息可能很有趣,但一开始就不应该起作用.鉴于动态类型系统,这实际上具有某种变态的意义.

                  Prior to PHP 7 type hinting can only be used to force the types of objects and arrays. Scalar types are not type-hintable. In this case an object of the class string is expected, but you're giving it a (scalar) string. The error message may be funny, but it's not supposed to work to begin with. Given the dynamic typing system, this actually makes some sort of perverted sense.

                  您只能手动输入提示"标量类型:

                  You can only manually "type hint" scalar types:

                  function foo($string) {
                      if (!is_string($string)) {
                          trigger_error('No, you fool!');
                          return;
                      }
                      ...
                  }
                  

                  这篇关于如何解析“必须是字符串的实例,字符串给定"在 PHP 7 之前?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:window.history.pushState 刷新浏览器 下一篇:PHP PDO::bindParam() 数据类型..它是如何工作的?

                  相关文章

                  最新文章

                  <legend id='Vobqo'><style id='Vobqo'><dir id='Vobqo'><q id='Vobqo'></q></dir></style></legend>
                  1. <tfoot id='Vobqo'></tfoot>

                      <bdo id='Vobqo'></bdo><ul id='Vobqo'></ul>

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

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