以下脚本位于名为 的目录中package_1
:
<?php
namespace ashaar;
class Ghazal {
public function nameIt() {
echo "Dekh to dil ke jaan se utha hai <br />";
}
}
并且以下脚本位于名为的目录中package_2
:
<?php
namespace package_1\ashaar;
require 'first.php';
$obj = new Ghazal();
$obj->nameIt();
当我运行上面的脚本时(在目录包 2 中)我得到一个错误:
Warning: require(\package_1\first.php): failed to open stream: No such file
or directory in /opt/lampp/htdocs/package_2/second.php on line 3
Fatal error: require(): Failed opening required '\package_1\first.php'
(include_path='.:/opt/lampp/lib/php') in /opt/lampp/htdocs/package_2/second.php
on line 3
这是为什么 ?