yii学习第一课 《命名空间》

<?php

namespace a\b\c;

class Apple {

    function getInfo() {
        echo 'this is a<br>';
    }

}
<?php

namespace d\e\f;

class Apple {

    function getInfo() {
        echo 'this is b<br>';
    }

}
<?php
class Apple {

    function getInfo() {
        echo 'this is C<br>';
    }

}

调用处:

<?php

require_once("A.php");
require_once("B.php");
require_once("C.php");
use a\b\c\Apple;
use d\e\f\Apple as BApple;

$a_app = new Apple();
$a_app->getInfo();

$b_app=new BApple();
$b_app->getInfo();

$c_app=new \Apple();
$c_app->getInfo();

this is a
this is b
this is C

你可能感兴趣的:(yii学习第一课 《命名空间》)