3
我仍然在學習使用PHP的作曲家作曲家PSR-4自動加載無法找到文件
我有這樣的目錄結構:
,這是我composer.json
{
"autoload": {
"psr-4": {
"Kct\\": "lib/"
}
}
}
現在在我的index.php文件中,我正試圖在tesdir.php中加載Class tes
<?php
// file: index.php
require __DIR__ . '/vendor/autoload.php';
$x = new \Kct\Tesdir\Tes();
var_dump($x->tes()); //output: 'GET'
我tesdir.php:
<?php
namespace Kct\Tesdir;
class Tes {
public function tes() {
return $_SERVER['REQUEST_METHOD'];
}
}
現在
,如果我在我的本地主機打開的index.php我和這樣的錯誤:
Fatal error: Uncaught Error: Class 'Kct\Tesdir\Tes' not found in /var/www/html/tesComposer/index.php:6 Stack trace: #0 {main} thrown in /var/www/html/tesComposer/index.php on line 6
有人可以解釋爲什麼?
謝謝dud,非常有幫助:)) – Herdy