PHP Fatal Error – Handling Deprecated Functionality in Magento 2.4.5

magento2.4.5

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;
}

Best Answer

You just need to add

: mixed

public function jsonSerialize() : mixed

Your issue will be fixed

Related Topic