Should I namespace global functions in PHP?

前端 未结 3 502
死守一世寂寞
死守一世寂寞 2021-01-02 00:49

In PHP, I\'m using namespaces at the class level. However, Netbeans keeps telling me namespace my global functions as well. For example, if I type

str_replac         


        
3条回答
  •  情深已故
    2021-01-02 01:11

    Netbeans is simply not following the documented rules of resolving namespaces as documented:

    1. global classes (like DateTime) need to be qualified otherwise, PHP will look for that class in the current namespace.
    2. global functions (like array_filter) and constants will be found in the global namespace (without explicit qualification) if they do not exist in the current namespace.

    In other words, your code should be considered idiomatic based on the documented rules.

提交回复
热议问题