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
3 Answers
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
-
4I can confirm this worked for me. Changed instances of \Zend_Json to \Laminas\Json\Json Commented Mar 21, 2023 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. Commented Jul 20, 2023 at 12:51
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']);
}
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);