I have composer.json file:
{
"name": "marko/art-empire",
"description": "Social network",
"type": "project",
"authors": [
{
"name": "Marko Ilic",
"email": "markowebdeveloper@gmail.com"
}
],
"require": {},
"autoload": {
"psr-4": {
"Songs\\": "songs/"
}
}
}
autoload_psr4.php file:
$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);
return array(
'Songs\\' => array($baseDir . '/songs'),
);
RandomSong.php file in songs folder (which is in root directory):
namespace Song;
class RandomSong
{
public function songName()
{
return 'Random Song';
}
}
test.php file:
require 'vendor/autoload.php';
use Songs\RandomSong;
$randomSong = new RandomSong();
echo $randomSong->songName();
As you can see I am trying to autoload RandomSong class, but I keep getting:
Fatal error: Uncaught Error: Class 'Songs\RandomSong' not found in test.php
Please help, thanks.