//namespace1.php <?php namespace Demo1; class test1 { private $name='www.php.cn'; public function getName() { return $this->name; } }
//namespace2.php <?php namespace Demo2; require('namespace1.php'); use Demo1\test1; class test1 { private $name='PHP中文网'; public function getName() { return $this->name; } }
The problem is why the following error occurs when I access namespace2.php
Fatal error: Cannot declare class Demo2\test1 because the name is already in use in
Do I have to give the class an alias when using Demo1\test1? ? 'as D1test1'????
Please guide me
零时差2020-07-08 23:11:28
The test1 class already exists in demo1. Then you applied the file require('namespace1.php'); and then referenced the demo1 class use Demo1\test1;
Do you think there will be no error? Can you give him an alias?