Problem with Composer - PSR-4

Asked

Viewed 83 times

0

I am studying Composer and its autoload forms (classmap, file, psr-0, psr-4), but in my example it is appearing with the following error:

Fatal error: Class 'Library\Exemplo' not found in/var/www/html/CursoPHP/composer/index.php on line 5

My example folder structure is this:

/ comp 
   |-- /src 
     |-- /Library 
           |-- exemplo.php
   |-- /vendor 
   |-- index.php 

My index.php:

require_once 'vendor/autoload.php';

$nome = new \Library\Exemplo();

My Komposer.json:

"autoload": {
    "psr-4": {
      "Library\\": "src/Library"
    }
}

My example.php:

<?php namespace Library;

  class Exemplo
  {
    public function __construct()
    {
      echo 'Classe Exemplo Iniciada';
    }
   }

 ?>

With all the other Poser autoload means I was successful, but I can’t find the error of my example using PSR-4.

  • 2

    Try to change "Library\\": "src/Library" for "": "src/", besides renaming the file exemplo.php for Exemplo.php (in block capitals).

  • @Rodrigorigotti the whole detail was really in the confusion of the file name, did not know that the default was "Casesensitive", in which case the class name has to be exactly the file name.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.