PHP class not found when using namespace

后端 未结 2 1560
孤城傲影
孤城傲影 2020-12-16 02:53

I am new with this namespace thing.

I have 2 classes(separate files) in my base directory, say class1.php and class2.php inside a directory

2条回答
  •  甜味超标
    2020-12-16 03:20

    You are going to need to implement an autoloader, as you have already read about it in SO.

    You could check the autoloading standard PSR-4 at http://www.php-fig.org/psr/psr-4/ and you can see a sample implementation of PSR-4 autoloading and an example class implementation to handle multiple namespaces here https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-4-autoloader-examples.md.

提交回复
热议问题