PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, February 9, 2022

[FIXED] Autoloading of classes through composer does not work

 February 09, 2022     composer-php, namespaces, php, psr-4     No comments   

Issue

I have a project structure:

enter image description here

In the index.php I create 2 new objects:

use App\Controllers\Test;
use Xuborx\Cms\App;

new Test();
new App();

My Test.php

<?php

namespace App\Controllers;

class Test
{

}

My App.php

<?php

namespace Xuborx\Cms;

class App {

}

My autoload object in composer.json:

"autoload": {
        "psr-4": {
            "App\\Controllers\\": "app/controllers",
            "Xuborx\\Cms\\": "vendor/xuborx/cms"

        }
    }

Object Test created successfully in the index.php, but when I am creating new App, I have an error:

Fatal error: Uncaught Error: Class 'Xuborx\Cms\App' not found in /home/denis/Coding/xuborx-cms/public/index.php:8 Stack trace: #0 {main} thrown in /home/denis/Coding/xuborx-cms/public/index.php on line 8

Also, when I run composer dump-autoload -o, I get error:

Class Xuborx\Cms\App located in ./vendor/xuborx/cms/core/App.php does not comply with psr-4 autoloading standard. Skipping.

I think, I not correct use autoload in composer.json, but I don't understand my error. Please< talk me about it.


Solution

App.php are inside /core directory :

autoload": {
        "psr-4": {
            "App\\Controllers\\": "app/controllers",
            "Xuborx\\Cms\\": "vendor/xuborx/cms/core"

        }
    }


Answered By - Lasouze
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home
View mobile version

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing