创建了两个类,C和D,都属于同一个namespace:func,在D的构造函数中实例化C并调用C里的cc方法,报找不到func下的C类。
//C.php
<?php
namespace func;
class C {
public function cc() {
echo 'this is C->cc';
}
}
//D.php
<?php
namespace func;
class D {
public function __construct() {
$c = new C();
$c->cc();
}
}
new D();
执行D.php,报错信息如下:
ClivedeMBP:Workspace clive$ php D.php
PHP Fatal error: Uncaught Error: Class 'func\C' not found in /Users/clive/Workspace/D.php:7
Stack trace:
#0 /Users/clive/Workspace/D.php(11): func\D->__construct()
#1 {main}
thrown in /Users/clive/Workspace/D.php on line 7
Fatal error: Uncaught Error: Class 'func\C' not found in /Users/clive/Workspace/D.php on line 7
Error: Class 'func\C' not found in /Users/clive/Workspace/D.php on line 7
Call Stack:
0.0010 352608 1. {main}() /Users/clive/Workspace/D.php:0
0.0029 352648 2. func\D->__construct() /Users/clive/Workspace/D.php:11
请问,同一个命名空间下的两个类应该怎么写,才能彼此调用啊?
- 2 回答
- 0 关注
- 304 浏览
添加回答
举报
0/150
提交
取消