2

I am adding some custom classes to a project. I am struggling to get psr-4 autoloading to work.

I am placing my custom classes in a folder at [project root]/lib Here is the autoload bit from my composer.json:

  "autoload": {
    "psr-4": {
        "App\\": "app/src",
        "Lib\\": "lib"
    }
},

I have a file P_Database.php in the lib folder with the following declarations:

 <?PHP
namespace Lib;

class P_Database
{
     //

I call the class in a file with:

 use Lib\P_Database;
 require __DIR__ . '/../vendor/autoload.php';
 $db = new P_Database();

I get a 500 error:

 PHP Fatal error:  Class 'Lib\\P_Database' not found....

I have run composer dump-autoload. Can anyone point me in the right direction?

Federkun
  • 36,084
  • 8
  • 78
  • 90
Roger Creasy
  • 1,419
  • 2
  • 19
  • 35

0 Answers0