How and where should I use the keyword “use” in php

后端 未结 3 1631
情话喂你
情话喂你 2021-01-14 06:41

I used use the keyword \"use\" generally above the class definition. Like this:



        
3条回答
  •  旧时难觅i
    2021-01-14 07:18

    In PHP, the keyword use is used in 3 cases:

    1. As class name alias - simply declares short name for a class (must be declared outside of the class definition) (manual: Using namespaces: Aliasing/Importing )
    2. To add a trait to a class (must be declared inside (at the top) of the class definition) (manual: Traits)
    3. In anonymous function definition to pass variables inside the function (manual: Anonymous functions)

提交回复
热议问题