使用依赖注入按文档操作后提示:must not be accessed before initialization
<?php
$builder = new \DI\ContainerBuilder();
$builder->addDefinitions(config('dependence', []));
$builder->useAutowiring(true);
$builder->useAttributes(true);
return $builder->build(
<?php
namespace app\controller\store;
use app\helpers\ApiResponse;
use app\helpers\BankCardCodeHelper;
use app\service\store\card\BankCardService;
use app\presenter\store\card\BankCardDetailPresenter;
use app\validator\BankCard\BindBankCardValidator;
use DI\Attribute\Inject;
use support\Request;
use support\Response;
class BankCardController
{
#[Inject]
private BankCardService $bankCardService;
public function detail(Request $request): Response
{
try{
$store_id = $request->user->store_id;
$result = $this->bankCardService->detail($store_id);
$formattedResult = BankCardDetailPresenter::format($result);
return ApiResponse::success($formattedResult);
} catch (\Throwable $e) {
return ApiResponse::error($e->getMessage().' '.$e->getLine());
}
}
"php-di/php-di": "^7.1",
"psr/container": "^2.0",
"doctrine/annotations": "^2.0"
请各位大佬指点一二
Typed property app\controller\store\BankCardController::$bankCardService must not be accessed before initialization 23