我在学习并试图理解在PHP中使用namespace
和use
。我也在php.net documentation上使用spl_autoload_register
。我仍然对使用它并产生错误感到困惑。PHP - spl_autoload_register不使用`namespace`和`use`
我有我的教程文件夹2个文件:
- php_oop.php
- tutor.php
php_oop.php
<?php
namespace php_oop;
class php_oop
{
public function __construct($name){
$this->name = $name;
}
public function get(){
return $this->name;
}
}
tutor.php
输出
Warning: The use statement with non-compound name 'php_oop' has no effect in C:\xampp\htdocs\tutorial\oop\tutor.php on line 9 string(7) "php_oop" Fatal error: Class 'php_oop' not found in C:\xampp\htdocs\tutorial\oop\tutor.php on line 11
我想知道如何正确使用它呢?
类名的第一个字母必须是大写。 – Nidhi
这只是一种文体,@Nidhi。 – Bytewave