PSR-4 autoloading class after structure changes


I think that it isn't a big problem. Probably I need a small change in my code. In my project I've the src/ directory which contains File.php and NoFileException.php files.


namespace myns;  use mynsNoFileException;
class File  {   ...  }  


namespace myns;
class NoFileException extends Exception  {   ...  }  


"autoload": {   "psr-4": {   "myns\": "src/"   }   }  

And everything works correctly. Now I would like to move the NoFileException.php at the src/Exception/ directory. Thus I changed src/File.php:

namespace myns;  use mynsExceptionNoFileException;
class File  {   ...  }  

and src/Exception/NoFileException.php:

namespace mynsException; // doesn't work  //namespace myns; // also does't work
class NoFileException extends Exception  {   ...  }  

And I receive a statement that class NoFileException not found. I also added to composer.json a new mapping and tried different combinations of namespaces (I did dump-autoload). There is no reason to present all my attempts. How to solve this problem?


The full message error when namespace in the src/Exception/NoFileException.php is myns looks like:

Fatal error: Uncaught Error: Class 'mynsExceptionNoFileException' not found in /home/project/src/File.php:21  Stack trace: #0 /home/project/src/File.php(15):  mynsFile->readable('r') #1 /home/project/index.php(20):   mynsFile->__construct('files/filename...') #2 {main} thrown in /home/project/src/File.php on line 21  

When namespace is mynsException the error message is the same but without Class word at the beginning.