1

After Magento Upgrade in latest version showing error under third party module

PHP Fatal error: During inheritance of JsonSerializable: Uncaught Exception: Deprecated Functionality: Return type of Aheadworks\Rbslider\Ui\Component\MassAction\Banner\Options::jsonSerialize() should either be compatible with JsonSerializable::jsonSerialize(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /app/code/Aheadworks/Rbslider/Ui/Component/MassAction/Banner/Options.php on line 83 in /vendor/magento/framework/App/ErrorHandler.php:62 Stack trace:

Options.php function is below which has showing error please suggest me what I do here?

/**
 * Get action options
 *
 * @return array
 */
public function jsonSerialize()
{
    if ($this->options === null) {
        $options = $this->collection->toOptionArray();
        $this->prepareData();
        foreach ($options as $optionCode) {
            $this->options[$optionCode['value']] = [
                'type' => $this->data['type'] . $optionCode['value'],
                'label' => $optionCode['label'],
            ];

            if ($this->urlPath && $this->paramName) {
                $this->options[$optionCode['value']]['url'] = $this->urlBuilder->getUrl(
                    $this->urlPath,
                    [$this->paramName => $optionCode['value']]
                );
            }

            $this->options[$optionCode['value']] = array_merge_recursive(
                $this->options[$optionCode['value']],
                $this->additionalData
            );
        }

        $this->options = array_values($this->options);
    }

    return $this->options;
}

3 Answers 3

1

You just need to add

: mixed

public function jsonSerialize() : mixed

Your issue will be fixed

2
  • After add this still showing issue PHP Fatal error: During inheritance of JsonSerializable: Uncaught Exception: Deprecated Functionality: Return type of Aheadworks\Rbslider\Ui\Component\MassAction\Status\Options::jsonSerialize() should either be compatible with JsonSerializable::jsonSerialize(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/html/gossip/app/code/Aheadworks/Rbslider/Ui/Component/MassAction/Status/Options.php on line 82 in /var/www/html/gossip/vendor/magento/framework/App/ErrorHandler.php:62 Commented Dec 27, 2022 at 11:23
  • problem was related to other file which has same function calling so I have changed same in both file. finally solve this, previous I was trying to put it with one file that's why error was showing. Commented Dec 28, 2022 at 6:19
0

This will definitely help you:

https://github.com/twigphp/Twig/issues/3534

Try this solution :

public function jsonSerialize()
{
    if ($this->options === null) {
        $options = $this->collection->toOptionArray();
        $this->prepareData();
        foreach ($options as $optionCode) {
            $this->options[$optionCode['value']] = [
                'type' => $this->data['type'] . $optionCode['value'],
                'label' => $optionCode['label'],
            ];

            if ($this->urlPath && $this->paramName) {
                $this->options[$optionCode['value']]['url'] = $this->urlBuilder->getUrl(
                    $this->urlPath,
                    [$this->paramName => $optionCode['value']]
                );
            }

            $this->options[$optionCode['value']] = array_merge_recursive(
                $this->options[$optionCode['value']],
                $this->additionalData
            );
        }

        $this->options = array_values($this->options);
    }

    return $this->options;
}
3
  • I have already put here :mixed and :string with function but its not work here. Commented Dec 27, 2022 at 11:20
  • I have updated my solution please check
    – Rana Zain
    Commented Dec 27, 2022 at 11:32
  • didn't find here proper solution, if you have please comment here what I do with this function. Commented Dec 27, 2022 at 12:03
0

The correct code is!

public function jsonSerialize() : array

Your Answer

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

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