search

Home  >  Q&A  >  body text

php - Why can't I declare a namespace using namespace \Common\Tool ; like this?

namespace \Common\Tool ; (Note there is a backslash at the beginning!!!!)

Common\Tool and \Common\Tool are the same. Why can't we add a backslash at the beginning when declaring the namespace?

The reason for the error is undefined constant CommonTool (undefined constant CommonTool). Why does the system determine this? Isn't it a rule that you can't add a backslash at the beginning? Looking forward to the answer, thank you all

怪我咯怪我咯2732 days ago944

reply all(4)I'll reply

  • 某草草

    某草草2017-06-06 09:55:43

    Because...this is the syntax of php...

    reply
    0
  • 大家讲道理

    大家讲道理2017-06-06 09:55:43

    This is a language specification, customized. If you want to use something else, you have to write your own code to handle this method. It is just like $a defining a variable. If you insist on %a defining one, it is absolutely fine, but you need Implement the explanation yourself.

    reply
    0
  • 巴扎黑

    巴扎黑2017-06-06 09:55:43

    Why challenge? Or question? PHP syntax. .

    reply
    0
  • 给我你的怀抱

    给我你的怀抱2017-06-06 09:55:43

    For example, there is a class in tp’s class library

    Represents the PHP system-level namespace

    reply
    0
  • Cancelreply