1

We're in the process of upgrading our store from Magento 2.4.2 to 2.4.4 and encountered the error shown in the image below. Please help us fix this issue.

enter image description here

Script in the project folder:

<?php

namespace StripeIntegration\Payments\Block\Customer;

use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\Framework\Filesystem;
use Magento\Framework\View\Element;
use StripeIntegration\Payments\Helper\Logger;

class Cards extends \Magento\Framework\View\Element\Template
{
    public function __construct(
        \Magento\Framework\View\Element\Template\Context $context,
        array $data = [],
        \StripeIntegration\Payments\Helper\Generic $helper,
        \Magento\Payment\Block\Form\Cc $ccBlock,
        \StripeIntegration\Payments\Model\Config $config
    ) {
        $this->stripeCustomer = $helper->getCustomerModel();
        $this->helper = $helper;

        $this->ccBlock = $ccBlock;
        $this->config = $config;

        parent::__construct($context, $data);
    }

    public function getCards()
    {
        try
        {
            return $this->stripeCustomer->getCustomerCards();
        }
        catch (\Exception $e)
        {
            $this->helper->addError($e->getMessage());
            $this->helper->logError($e->getMessage());
            $this->helper->logError($e->getTraceAsString());
        }
    }

    public function verifyBillingAddress()
    {
        $address = $this->helper->getCustomerDefaultBillingAddress();

        if (!$address || empty($address->getStreet()))
            return false;

        return true;
    }

    public function getCcMonths()
    {
        return $this->ccBlock->getCcMonths();
    }

    public function getCcYears()
    {
        return $this->ccBlock->getCcYears();
    }

    public function cardType($code)
    {
        return $this->helper->cardType($code);
    }
}

2 Answers 2

5

This is means that in your block you define optional argument before another required, like:

public function __construt($data = [], SomeClass $required)
{
    //...
}

You need to change order of variables to first required and only after optional (predefined)

public function __construt(SomeClass $required, $data = [])
{
    //...
}

[Update]

In your case it should be

// ...
    public function __construct(
        \Magento\Framework\View\Element\Template\Context $context,
        \StripeIntegration\Payments\Helper\Generic $helper,
        \Magento\Payment\Block\Form\Cc $ccBlock,
        \StripeIntegration\Payments\Model\Config $config,
        array $data = []
    ) {
        $this->stripeCustomer = $helper->getCustomerModel();
        $this->helper         = $helper;
        $this->ccBlock        = $ccBlock;
        $this->config         = $config;

        parent::__construct($context, $data);
    }
// ...
4
  • Thanks, Victor. I copy pasted the script contents for you to have a look. Aug 25, 2022 at 17:48
  • See update in answer, I hope you understand the idea of changes. Aug 25, 2022 at 17:52
  • Yes, it is clear, thanks Aug 25, 2022 at 17:59
  • @VictorTihonchuk what is quick solution ? if number of 1000 construct() method and function method optional param before required params? Will we change all thousand of methd change or any other quick solution? can we ignore this exception because In my case 150+ module installed and thousand of error face.
    – HaFiz Umer
    Oct 18, 2022 at 12:21
0

you can use ?type instead in your case : ?array $data, read more here: https://php.watch/versions/8.0/deprecate-required-param-after-optional

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.