当前位置:Gxlcms > PHP教程 > phpnamespace引起的问题

phpnamespace引起的问题

时间:2021-07-01 10:21:17 帮助过:2人阅读

a . PHP_EOL;
    }
}

class test2 {
    public function hello(){
        $obj = new test1;
        //var_dump(get_class($obj)); //always abc\test1
        $obj->hello();
    }
}

namespace def;
class test1 extends \abc\test1 {
    public $a = ' bbb';
}

class test2 extends \abc\test2 {

}



(new test2)->hello();

求教:
不改动abc命名空间的代码的情况下, 如何在 def\test2 调用 def\test1 而不是 abc\test1

回复内容:

a . PHP_EOL;
    }
}

class test2 {
    public function hello(){
        $obj = new test1;
        //var_dump(get_class($obj)); //always abc\test1
        $obj->hello();
    }
}

namespace def;
class test1 extends \abc\test1 {
    public $a = ' bbb';
}

class test2 extends \abc\test2 {

}



(new test2)->hello();

求教:
不改动abc命名空间的代码的情况下, 如何在 def\test2 调用 def\test1 而不是 abc\test1

下面这段这么修改:

namespace def;
class test1 extends \abc\test1 {
    public $a = ' bbb';
}

class test2 extends test1 {

}


$a= new \def\test2();
print_r($a->hello());

人气教程排行