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.
src
inside ofvendor
directory? – rob006vendor
directory is only for dependencies and should be fully managed by Composer - at any point you should be able to remove it and restore it by callingcomposer install
. Don't put your own files inside of it. – rob006