名为 tester.php 的脚本
<?php
namespace my;
class Tester {
public function greet() {
echo "Hello ! <br />";
}
}
一个名为tester1.php的新脚本:
<?php
use my;
$obj = new Tester();
$obj->greet();
当我运行时,tester1.php
我收到此错误:
Warning: The use statement with non-compound name 'my' has no effect
in /opt/lampp/htdocs/tester_1.php on line 2
Fatal error: Class 'Tester' not found in /opt/lampp/htdocs/tester_1.php on line 4
为什么我会收到此错误?这两个脚本都在同一个目录/opt/lampp/htdocs/
中。