namespace使用

  demo.php

<?php
namespace MyName;
class test{
    public function ceshi(){
        echo 'hello world';
    }
}


namespace Name;

class test{
    public function ceshi(){
        echo 'hello  你妹';
    }
}

test.php

<?php  
include('../controller/demo.php');

use name\test;

$demo = new test();
$demo->ceshi();// hello 你妹

自己总结的,刚刚摸索。

命名空间主要作用应该是为了不让函数或者类重复,方便知道是调用的哪个而已。

use   后面跟的是你命名空间的内容   +  ‘\’ (这里不能写反,'/'这个是没用的) + 类名。

猜你喜欢

转载自blog.csdn.net/jueyan520/article/details/84838063