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 Answers3

1

You just need to add

: mixed

public function jsonSerialize() : mixed

Your issue will be fixed

Arun Sharma
  • 1,315
  • 1
  • 9
  • 33
  • 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 – Aashutosh Kumar Dec 27 '22 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. – Aashutosh Kumar Dec 28 '22 at 06: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;

}

Rana Zain
  • 652
  • 2
  • 12
0

The correct code is!

public function jsonSerialize() : array