namespace
Estimated reading time: 1 minutewhat is namespace
namespace is a indicator for file . you can use specific file with specific namespace . namespace keyword is namespace
namespace
live
top
level in thefile
. (first declare
)case-insensitive
- sub directory with
\
backslash
why use namespace
escape
namecollision
with othersfile/folder/code
- ability to use
large file
name with aliasas
veryshortyly
.
<?php
namespace User\Info;
class profile {
function user() {
echo("function name isn't case-sensitive");
}
}
?>
how access namespace
- access by
use
keyword - alias wirh
as
keyword
<?php
use User\Info;
use User\Info as client;
class Test{
}