Uncaught ArgumentCountError: Too few arguments to function Interceptor.php on line 14 and at least 2 expected in ….

PHP Fatal error:  Uncaught ArgumentCountError: Too few arguments to function Equaltrue\\Themeoption\\Controller\\Taxmode\\Index::__construct(), 1 passed in
/var/www/html/equaltrue.com/dev_version/generated/code/Equaltrue/Themeoption/Controller/Taxmode/Index/Interceptor.php on line 14
and at least 2 expected in
/var/www/html/equaltrue.com/dev_version/app/code/Equaltrue/Themeoption/Controller/Taxmode/Index.php:21
Stack trace:
#0 /var/www/html/equaltrue.com/dev_version/generated/code/Equaltrue/Themeoption/Controller/Taxmode/Index/Interceptor.php(14): Equaltrue\\Themeoption\\Controller\\Taxmode\\Index->__construct(Object(Magento\\Framework\\App\\Action\\Context))
#1 /var/www/html/equaltrue.com/dev_version/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php(111): Equaltrue\\Themeoption\\Controller\\Taxmode\\Index\\Interceptor->__construct(Object(Magento\\Framework\\App\\Action\\Context))
#2 /var/www/html/equaltrue.com/dev_version/vendor/magento/framework/ObjectManager/Factory/Dynamic/Developer.php(66):
Mag in /var/www/html/equaltrue.com/dev_version/app/code/Equaltrue/Themeoption/Controller/Taxmode/Index.php on line 21,
referer: http://localhost/equaltrue.com/dev_version/

These things happen for those Code: Moving the position of bold element

<?php
namespace Equaltrue\Themeoption\Controller\Taxmode;
use Magento\Framework\App\Action\Context;
use Magento\Framework\Data\Form\FormKey\Validator;
use Magento\Framework\App\ObjectManager;

class Index extends \Magento\Framework\App\Action\Action
{

    /**
     * @var Validator
     */
    private $formKeyValidator;
    protected  $customerSession;

    /**
     * @param Context $context
     * @param Validator $formKeyValidator
     * @param \Magento\Customer\Model\Session $customerSession
     */
    public function __construct(
        Context $context,
        \Magento\Customer\Model\Session $customerSession,
        Validator $formKeyValidator = null
    )
    {
        $this->customerSession = $customerSession;
        $this->formKeyValidator = $formKeyValidator ?: ObjectManager::getInstance()->get(Validator::class);
        parent::__construct($context);
    }
}

Now this thing is Fixed by :

public function __construct(
    Context $context,
    \Magento\Customer\Model\Session $customerSession,
    Validator $formKeyValidator = null
)
{
    $this->formKeyValidator = $formKeyValidator ?: ObjectManager::getInstance()->get(Validator::class);
    parent::__construct($context);
    $this->customerSession = $customerSession;
}

Was this article helpful?

Related Articles

Leave A Comment?