How to autoload a class with a different filename? PHP

I would like to autoload the class, but it was declared inside a different filename like this:

AClass.php

namespace path\to\A;

class AClass {}

class AException extends \Exception {}

      

BClass.php

namespace path\to\B;

use path\to\A\AClass; // I'm actually after AException inside

class BClass {}

class BException extends AException {}

      

I'm not interested in loading AClass, but AException. However, the above code is not autoloading AException.

0


source to share


1 answer


The convention may dictate that the filename matches the class internally, but that's just a convention. Your autoloader can use whatever mapping you find useful. You can always find the class name xxxxxException and map it to xxxxxClass.php



+1


source







All Articles