The use
keyword is not only involved in the oriented process ofPHP
, It also steals the show inPHP
object-oriented. In the actual development process, it is also spread throughout the source code. This article will make a summary of theuse
keyword.
1. Reference for namespace
2. Keyword for alias
namespace space; function display(){} class Man{} const PI = 3.14; namespace space1; class Man{} //引入空间元素 //use space\Man; //错误:当前空间已经存在Man use space\Man as M; use function space\display as dis; use const space\PI as D;
3. Used for the introduction of trait feature capabilities
testTrait(); ?>
4. In anonymous functions Reference local variables in
Recommended:《2021 PHP interview questions summary (collection)》《php video tutorial》
The above is the detailed content of Use keyword in various aspects of life in PHP. For more information, please follow other related articles on the PHP Chinese website!