Synthiatic
Synthiatic

Reputation: 261

Composer Class loading: Doesn't find classes

Hi there,

I'm fairly new in working with composer, but I'm experiencing issues. After some stackoverflow searches I tried some of te solutions, however, none of them did work for me. I Have the following error:

Fatal error: Class 'Freeby\Basic\Navigator' not found in index.php on line *.

So I took a look at my index. It contains the following code: index.php

namespace Freeby;

use \Freeby\Basic\Navigator as Navigator;

Navigator::execute();

The line where the error occurs is the last one, Navigator::execute();. So I went to take a look at this class found in the folder Basic. Navigator.php

namespace Freeby\Basic;

class Navigator
{

    public static function execute()
    {

    }

}

So, I have my namespace there. It should be recognized. However, it does not. So I went on to check my composer.json.

{
    "require": {
        "mikecao/flight": "^1.3"
    },
    "autoload": {
        "psr-4": {
            "Freeby\\Basic\\": "Basic/"
        }
    }
}

And I think this one is correct. However I'm not that sure. To be sure I'll include my structure here too. Maybe it's a path issue? If yes, why? I Couldn't find it.

---- Basic
- Navigator.php
---- Vendor
- autoload.php
-- composer
---- composer.json

Upvotes: 1

Views: 865

Answers (1)

Dolly Aswin
Dolly Aswin

Reputation: 2794

I think you need to load the composer autoloader first in index.php

<?php

namespace Freeby;

require __DIR__."/vendor/autoload.php";

use \Freeby\Basic\Navigator as Navigator;

Navigator::execute();

Upvotes: 3

Related Questions