Home » Php » PSR4 not working?

PSR4 not working?

Posted by: admin October 29, 2018 Leave a comment

Questions:

Class not found, apparently. I’ve tried various things but nothing works.

Composer:

"autoload": {
    "psr-4": {
        "App\": "application/"
    }
}

File structure:
https://i.imgur.com/h9wOEqI.png

<?php

namespace App\Library\Classes;

defined('START') or exit('We couldn\'t process your request right now.');

class Application
{
    private static $libraries = array();

    public static function get($library) {
        if (isset(self::$libraries[$library]) && isset(self::$classes[$library])) {
            return self::$libraries[$library];
        }

        $fixedLibrary = str_replace('.', '/', $library);
        $file = ROOT . '/application/library/classes/' . strtolower($fixedLibrary) . '.php';

        self::$libraries[$library] = $library;

        $declared = get_declared_classes();
        $workingClass = end($declared);

        self::$libraries[$library] = new $workingClass();

        return self::$libraries[$library];
    }
}

?>

Error is on this line:

Application::get('test')->test();

Yet, if I change it to this, it works:

include ROOT . '/application/Library/Application.php';
App\Library\Classes\Application::get('test')->test();
Answers: