Slim 显示 class 未找到错误,即使 class 存在

Slim shows class not found error, even though class exists

我有一个文件Sample.php,其中我需要另一个文件Sample2.php。我的目录结构如下:

\main directory
   \vendor
        \Sample2.php
   \Sample.php
   \myFile.php`

Sample2.php 的命名空间声明为 namespace MySample\Practice。 但是当我将 Sample2.php 包含在 Sample.php 中作为

use MySample\Practice\Sample2.php

它给出错误 无法打开流:没有这样的文件或目录。我认为它无法加载自动加载 file.Also myFile.php具有相同的代码,但它正在工作,而 Sample.php 中的代码有一些额外的东西不工作。我该怎么办?

Sample.php

 use MySample\Practice\Sample2.php;
 $sample2=new Sample2();
 $sample->myFunction();
 //Some other code over here.

Sample2.php

 namespace MySample\Practice;
 class Sample2{
     function_construct(){}
     function myFunction(){}
}

正常运行的代码myFile.php

 use MySample\Practice\Sample2.php;
 $sample2=new Sample2();
 $sample->myFunction();

已添加

require_once __DIR__ . './vendor/autoload.php';

它工作正常。