Use external class in drupal 8 module with file name and class name I have created a module in drupal 8 .
I need to use a class which is in external file .

File name : drupal.php

Class name : class newman{...}

In drupal.php ( have many classes ):

&lt;?php
namespace Drupal\mymodulename\lib;
class newman{
   public function new(){
       $dp = 'TEST';
       return $dp;
   }
}
?&gt;


In my controller :

&lt;?php
namespace Drupal\mymodulename\Controller;

use Drupal\Core\Controller\ControllerBase;
use Drupal\mymodulename\lib\drupal;

class mmController extends ControllerBase {
    public function man() {
          $this-&gt;man=new newman();
          $build['test'] = [
                            '#markup' =&gt; $man-&gt;new(),
                           ];
    }
}


Error: Class 'Drupal\mymodulename\Controller\newman' not found in Drupal...

How can I fix it ?
Your use statement is wrong. It should be:

use Drupal\mymodulename\lib\newman; - no Drupal on the end.

Aside from that, you should strive to inject dependencies in the constructor.

Also, there should not be a difference between the file name and classname. It makes it harder to debug and organize. The file should be named newman.php not drupal.php.

The error is referencing the fact that it cannot locate your class at the given namespace. It would help to brush up on PSR-4/autoloading in Drupal 8 as well as naming conventions and standards.