1.如果不加命名空间
test1.php
function test()
{
echo 'test1';
}
test2.php
function test()
{
echo 'test2';
}
test.php
require 'test1.php';
require 'test2.php';
报错:
2.加了命名空间
test1.php
namespace Test1;
function test()
{
echo 'test1';
}
test2.php
namespace Test2;
function test()
{
echo 'test2';
}
test.php
require 'test1.php';
require 'test2.php';
Test1\test();
echo '<br/>*************<br/>';
Test2\test();
3.简介
3.1定义命名空间
test2.php
namespace Test2;
function test()
{
echo 'test2';
}
test.php
namespace Test2;
function test()
{
echo 'test123';
}
test1.php
require 'test2.php';
require 'test.php';
test();
报错:
3.2定义子命名空间
3.3在同一个文件中定义多个命名空间