我对composer.json
中的自动加载感到很困惑:
我的项目结构如下:
/
app.php
composer.json
src/
Human.php
Human.php
像这样:
<?php
namespace Society;
class Human {
var $name;
function __construct() {
print("Constructing human");
}
function getName() {
return $this->$name;
}
}
app.php
就像:
<?php
use Society\Human;
$h1=new Society\Human();
$h1->getName();
最后我的composer.json
就像:
{
"name": "tr/society-emulation",
"require": {
"php": ">=5.5.0",
"monolog/monolog": "^1.17"
},
"require-dev": {
"phpunit/phpunit": ">=4.8 < 6.0"
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
}
},
"config": {
"process-timeout" : 0
},
"autoload": {
"psr-4": {
"Society\\": "src/"
}
}
}
当我运行app.php
时,错误提示为:Class 'Society\Human' not found
。
有人可以提示如何使事情正常吗?