1
class CustomSawException extends Exception implements ServiceLocatorAwareInterface, SawExceptionInterface
{
    protected $serviceLocator;

    public function test(){
        $this->serviceLocator->get('SomeThing');
    }

    /**
     * Set service locator
     *
     * @param ServiceLocatorInterface $serviceLocator
     */
    public function setServiceLocator(ServiceLocatorInterface $serviceLocator)
    {
        $this->serviceLocator = $serviceLocator;
    }

    /**
     * Get service locator
     *
     * @return ServiceLocatorInterface
     */
    public function getServiceLocator()
    {
        return $this->serviceLocator;
    }

これに対してスローされる例外は次のとおりです。

null での get() の呼び出し

なぜ例外がスローされているのかわかりませんでしたか? ServiceLocatorAwareInterfaceを注入する必要がありましたServiceLocatorか?

4

2 に答える 2