Reputation: 165
I have a base folder with a vendor folder which include composer folder and my created folder src. The src folder contain all classes required to work.
In src folder, I have class example below
<?php
namespace Test;
class Example{
public function display(){
echo "This is Example Class";
}
}
?>
my composer.json has following content:
{
"autoload":{
"psr-4":{
"Test\\":"src"
}
}
}
and finally I am creating the instance of example class in a test file in base folder:
<?php
require 'vendor/autoload.php';
$a=new Test\Example();
$a->display();
?>
The issue is when i try to run test file the following error occurred: [Fatal error: Uncaught Error: Class 'Test\Example' not found.]
Please help me what I am doing wrong, Here is the screen shot of directory structure. Thanks in advance.
Upvotes: 1
Views: 2406
Reputation: 111889
To be honest I'm not sure where your src
, testing.php
and composer.json
are located, but they should be located in main directory (in your case 2-Basic-example and not in vendor
directory). Then just run:
composer dump-autoload
and it should work assuming your Example
class is saved as Example.php
in src
directory
Upvotes: 3