1.代码
<?php
namespace beijing\haidian;
header('content-type:text/html; charset=utf-8');
class animal1{
public $obj='dog';
static $name='大黄';
}
function getmsg(){
echo '北京海淀';
}
const mn ='tongpan0';
namespace shanghai\putuo;
header('content-type:text/html; charset=utf-8');
class animal2{
public $obj='pig';
static $name='哼哼';
}
const mn ='tongpan';
function getmsg(){
echo '上海普陀';
}
//1.非限定名称访问方式
//getmsg();
//echo mn;
//2.完全限定名称访问方式
//\beijing\haidian\getmsg();
//$db = new \beijing\haidian\animal1();
//echo $db -> obj;
//echo \beijing\haidian\animal1 ::$name;
//3.限定名称访问方式
//use beijing\haidian;//引入空间
//haidian\getmsg();
//$da = new haidian\animal1();
//echo $da->obj;
//echo haidian\animal1::$name;
use \beijing\haidian\animal1;//引入类
echo animal1::$name;
$dc = new animal1();
echo $dc->obj;
?>
2.运行结果