You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
649 B
26 lines
649 B
<?php
|
|
namespace Project1;
|
|
include "01.php";
|
|
|
|
//两个文件使用同一个命名空间,变量/常量名会冲突吗?
|
|
//const var1=2; //wrong;会与01.php中的var1冲突
|
|
|
|
function fn2(){
|
|
echo "hello";
|
|
}
|
|
|
|
class ClassB{
|
|
public $var="world";
|
|
}
|
|
|
|
$obj=new ClassA;
|
|
echo $obj->var.PHP_EOL;
|
|
|
|
echo $var1;
|
|
|
|
/**
|
|
* 在02.php中使用01.php的命名空间,需要include"01.php"
|
|
* 说明01.php中的namespace Project1的作用范围就是01.php内
|
|
* 虽然02.php的命名空间也是Project1,但如果要使用其实文件中的命名空间,还是需要inlcude
|
|
*/
|
|
?>
|