문제

I'd like to autoload a class, but it's declared inside a different class' filename like so:

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.

도움이 되었습니까?

해결책

Convention might dictate that the file name matches the class inside, but that's only convention. Your autoloader is welcome to use any mapping you find useful. You can always look for a class name of xxxxxException and map it to xxxxxClass.php

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top