我namespace
在下面这样的课程中使用,
class_tidy.php,
namespace foo;
class tidy {
public function hello() {
echo 'Hello';
}
}
索引.php,
class MyAutoloader
{
public static function load($className)
{
$parts = explode('\\', $className);
require 'classes/class_'.end($parts) . '.php';
}
}
spl_autoload_register("\MyAutoloader::load");
$test = new foo\tidy();
$test->hello();
它工作得很好,但我想知道我是否可以访问该课程,而不是,
$test = new foo\tidy();
但,
$test = new foo::tidy();
哪个看起来更漂亮。但有了这个错误,
解析错误:语法错误,意外的 T_STRING,期待 T_VARIABLE 或 '$' ...