Problem with composer autoloading: not loading all files

I've been building my own web application for a while now, but hit the wall completely with a fatal error in PHP.

Storytelling: I'm working on the login / user part of the project. login.php

processes the login items and student.php

processes the account stuff.

When trying to terminate, doLogin

I get a fatal error that claims to be student::getProfile()

an "undefined method". student::getProfile()

called the part validate()

within the class login

.

Any help would be greatly appreciated! Thank:)

EDIT: With the help of @deceze, I was able to narrow down the problem to the point that Composer does not autoload all of my classes; only some. Can anyone help?

EDIT 2: I checked autoload_classmap.php

which Composer generated and all my main classes and models are listed! If they are listed in the classmap, why isn't Composer loading them?


project directory

application/
    config/
    controller/
    core/
        (core items such as auth, app, view rendering + view controller)
    model/
        (speciality functions such as login, registration + user)
    view/
public/
    index.php
    .htaccess
vendor/
    autoload.php
composer.json
.htaccess

note: /public/index.php calls `require '../vendor/autoload.php';`

      


composer.json

"autoload": {
    "psr-4": {
        "": [
            "application/core/",
            "application/model/"
        ]
    }
}

      

+3


source to share


1 answer


After a long tedious search, I found a bug in my paths - and it's pretty silly!

I have a named controller student

that also has a named model student

, and as such I was inadvertently trying to call a class that is technically already called . So he was looking in the first class student

for the function and not the other that actually contained that particular function.

Composer does not understand if there is already a class with the specified name that was previously declared and simply negates it without writing to the PHP error log.

To avoid this mistake - and any further combinations of class names in the future, I decided to use separate namespaces for classes core

and model

. This separates these classes into "subsections" as such, allowing classes with the same (albeit in different namespaces) to be used.




PHP Manual: Namespaces

Sitepoint: Using PHP Namespaces, Part 1: The Basics

+1


source







All Articles