7

I have a theme and extensions that use widely the Zend_Json function i.e.for example : window.checkout = getConfig()); ?>; in 2.4.5 I had no problem using this code, in 2.4.6 it throws an exception : " main.CRITICAL: Error: Class "Zend_Json" not found in" I have the laminas package...what can go wrong ? TIA for help

0

3 Answers 3

16

Zend usage deprecated since 2.4.6 Now you can use Laminas. Usage: replace Zend_Json with \Laminas\Json\Json Be sure that you have installed laminas/laminas-serializer

2
  • 4
    I can confirm this worked for me. Changed instances of \Zend_Json to \Laminas\Json\Json Mar 21 at 13:34
  • Please avoid this lib to avoid future incompatibility issue. And it does not needed, because Magento has own class to work with Json in native Magento way. See my answer below. Jul 20 at 12:51
1

I. Magento 2.4.6 doesn't require laminas/laminas-serializer out-of-the-box. It requires laminas/laminas-json. You can use laminas/laminas-json.

II. But there is a more proper way:

\Magento\Framework\Serialize\Serializer\Json->serialize()
\Magento\Framework\Serialize\Serializer\Json->unserialize()

just to add object in your __construct().

    public function __construct(
        private readonly \Magento\Framework\Serialize\Serializer\Json $jsonSerializer
    ) {
        $string = $this->jsonSerializer->serialize(['data' => 'to_encode']);
    }

0

You can use like following

Magento 2.4.3
\Zend_Json::decode($infoRequestOption->getData('value'),true);

Magento 2.4.6
\Laminas\Json\Json::decode($infoRequestOption->getData('value'),true);

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.