What is a namespace and how is it implemented in PHP?

后端 未结 4 1887
清歌不尽
清歌不尽 2021-02-03 14:28

I\'ve heard the latest PHP has support for namespaces. I know variables defined in the global scope have no namespace, so how does one make a variable in a different na

4条回答
  •  鱼传尺愫
    2021-02-03 15:07

    A namespace allows you to organize code and gives you a way to encapsulate your items.

    You can visualize namespaces as a file system uses directories to group related files.

    Basically namespaces provide you a way in which to group related classes, functions and constants.

    They also help to avoid name collisions between your PHP classes/functions/constants, and improve the code readability, avoiding extra-long class names.

    Example namespace declaration:

    
    

提交回复
热议问题