-1

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.

Marko
  • 1
  • 2

2 Answers2

0

Your namespace is called Song, but you refer to it as Songs

Henrik Erstad
  • 681
  • 3
  • 11
  • 21
0

Your RandomSong uses Song namespace, while your loader is for Songs namespace.

Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141