php - How to use namespaces in non space classes? -


Is there a way to use namespace classes in non-namespace classes?

Example:

  // Note, class A and B. have no namespace ... extension of class A B {public functions () {$ obj = new My \ Namespace \ SomeObject (); Return $ obj; }}   

Thank you.

Just use the operator:

    

or you can use a fully qualified name, eg:

  $ obj = new \ My \ Namespace \ SomeObject () ;   

Pay attention to the major backslash. Contained namespace, because in fact there is no non-nomenclature):

  1. No requires a leading backslash.

  2. Using namespace is a syntax error because it does not matter in a reserved word (case is PHP because class, method and function Many keywords with names are case-insensitive).
  3. Using do is a syntax error, as it is also a reserved word ( do / while control Structure).

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -