<bdo id='24Ahd'></bdo><ul id='24Ahd'></ul>

  1. <tfoot id='24Ahd'></tfoot>

    <small id='24Ahd'></small><noframes id='24Ahd'>

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

      在 PHP 中导入类和命名空间:前导反斜杠有什么区

      时间:2023-09-24
        <tbody id='BONLg'></tbody>

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

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

          <tfoot id='BONLg'></tfoot>

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

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

                本文介绍了在 PHP 中导入类和命名空间:前导反斜杠有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                这两者有什么区别:

                use Exception;
                use Exception;
                

                或者那些:

                use FooBar;
                use FooBar;
                

                手册 说:

                请注意,对于命名空间名称(完全限定的命名空间名称包含命名空间分隔符,例如 FooBar与全局名称相反不是,例如 FooBar),领先的反斜杠是不必要的,而不是允许,因为导入名称必须完整合格,不处理相对于当前命名空间.

                Note that for namespaced names (fully qualified namespace names containing namespace separator, such as FooBar as opposed to global names that do not, such as FooBar), the leading backslash is unnecessary and not allowed, as import names must be fully qualified, and are not processed relative to the current namespace.

                但我真的不明白这一点,因为上述所有变体都有效,即绝对不是不允许"的.

                But I don't really understand this, as all of the above variants work, i.e. it definitely is not "not allowed".

                查看 zend_do_use 表明,is_global(设置,当有前导反斜杠时)仅用于以下情况的警告:

                A look into zend_do_use showed, that is_global (set, when there is a leading backslash) is only used for a warning in the following case:

                namespace {
                    use Exception;
                }
                

                这告诉我:具有非复合名称 'Exception' 的 use 语句无效".(虽然对 use Exception 做同样的事情会产生同样的影响,但不会发出警告.)

                Which tells me: "The use statement with non-compound name 'Exception' has no effect". (Though doing the same with use Exception would have just as little effect, but does not throw a warning.)

                所以:我错过了什么吗?真的有区别吗?

                So: Am I missing something? Is there actually some difference?

                推荐答案

                手册将反斜杠指定为不必要,这自然意味着如果您仍然使用它,则其含义是等效的.但是,正如您所指出的,手册上说这是不允许的,这是错误的.

                The manual specifies the backslash as unnecessary, which naturally means that if you still use it that the meaning is equivalent. However, as you have pointed out, the manual says that it is supposedly not allowed, which is false.

                但是,手册还有其他问题.他们做广告:

                However, there is something else troubling with the manual. They advertise this:

                // importing a global class
                use ArrayObject;
                

                如果导入名称确实没有相对于当前命名空间进行处理,那么 use ArrayObjectuse ArrayObject 必须具有相同的含义.除了全局对象之外,use ArrayObject 还能引用什么?在实践中,引擎会导入全局的.

                If it is true that import names are not processed relative to the current namespace, then use ArrayObject and use ArrayObject must have the same meaning. What else could use ArrayObject refer to other than the global one? In practice, the engine will import the global one.

                此外,还有这样的错误:http://bugs.php.net/bug.php?id=49143

                Also, with bugs such as this: http://bugs.php.net/bug.php?id=49143

                我认为对于标准应该是什么存在混淆.

                I believe there is confusion over what the standard is supposed to be.

                回答你的问题:没有区别.但是,如果我是引擎开发者,同时也是无前导斜杠标准的信徒,那么我就不需要考虑有人写use Exception; 的情况.我相信这很可能是这种情况.

                To answer your question: there is no difference. However, if I was the engine developer who was also a believer of the no-leading-slash standard, then I wouldn't need to consider a case where someone wrote use Exception;. I believe this was likely the case.

                这篇关于在 PHP 中导入类和命名空间:前导反斜杠有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:如何将var_export的输出读入PHP中的变量? 下一篇:SimplePie 可以从提要中抓取图像吗

                相关文章

                最新文章

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

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

                    <tfoot id='jDQNu'></tfoot>

                    • <bdo id='jDQNu'></bdo><ul id='jDQNu'></ul>