How to Fix “Class Zend Not Found” Issue in Magento 2
On March 14, 2023, Adobe released Magento 2.4.6, a highly anticipated update that included more than 300 quality fixes and platform enhancements. While this release was expected to bring about positive changes, it also introduced a significant modification that affects backward compatibility. Specifically, the Zend framework was deprecated, leading to the emergence of the “Class Zend Not Found” issue for users who recently upgraded to Magento 2.4.6. In this blog post, we will guide you through the necessary steps to resolve this issue and ensure the smooth functioning of your Magento 2 store.
Causes of the “Class Zend Not Found” Error
The main cause of the “Class Zend Not Found” error in Magento 2.4.6 is Adobe made the decision to deprecate the Zend framework from the Magento codebase and replace it with Laminas, a fork of the Zend framework.
The decision to switch from Zend to Laminas was made to leverage the advancements and improvements offered by the Laminas project, which provides a more robust and modern framework for PHP development.
However, this transition means that any custom code, third-party modules, or extensions that rely on Zend classes may no longer be compatible with Magento 2.4.6. The removal of the Zend framework can lead to the “Class Zend Not Found” error when the system attempts to instantiate or use Zend classes that have been replaced by their Laminas equivalents.
To resolve this error, it is necessary to update the affected codebase, including custom code and third-party modules, to use the corresponding Laminas classes instead of the deprecated Zend classes. Or in a more straightforward way (not recommended), you can re-add Zend framework to Magento as a temporary measure
Common Messages when Encountering Class Zend Not Found Error
- Error: Class “Zend_Json” not found.
- Error: Class “Zend_Http_Client” not found.
- Error: Class “Zend_Validate” not found.
- Error: Class “Zend_Filter” not found.
These common error messages help identify specific Zend classes that are causing the “Class Zend Not Found” error. It is crucial to update the codebase to utilize the corresponding Laminas classes or consider reintroducing the Zend framework if feasible.
Methods to fix Class Zend Not Found error
Method 1: Update Codebase and Modules with Laminas:
Step 1: Install Laminas
You need to install the Laminas package, specifically the laminas/laminas-serializer
, within your Magento 2 installation. This package will serve as a replacement for the deprecated Zend classes. Follow these steps to install Laminas:
- Open your terminal or command prompt.
- Navigate to your Magento 2 root directory.
- Run the following command:
composer require laminas/laminas-serializer
You can skip this step if your Magento already has laminas package.
Step 2: Replace Zend Classes with Laminas
After installing the Laminas package, it’s essential to replace the deprecated Zend classes with their corresponding Laminas classes. Follow these steps:
- Identify the .phtml file(s) that trigger the “Class Zend Not Found” error.
- Search for instances of Zend classes mentioned in the error message.
- Replace each Zend class with the appropriate Laminas class based on the following mappings:
Zend Classes | Laminas Classes |
---|---|
\Zend_Http_Client::POST | \Laminas\Http\Request::METHOD_POST |
\Zend_Http_Client::GET | \Laminas\Http\Request::METHOD_GET |
\Zend_Json | \Laminas\Json\Json |
\Zend_Validate | laminas-validator |
\Zend_HTTP | laminas-http |
\Zend_Filter | laminas-filter |
Update: Some other functions and classes
Zend Functions | Laminas Functions |
---|---|
\Zend_Validate::is($email, ‘EmailAddress’) | \Laminas\Validator\StaticValidator::execute($email, ‘EmailAddress’) |
Zend\Validator\EmailAddress | Laminas\Validator\EmailAddress |
\Zend_Filter_Input | \Magento\Framework\Filter\FilterInput |
- Save the modified files.
Method 2: Install Zend Framework into Magento
If your custom extensions heavily rely on Zend and updating them to use Laminas is not feasible, you can consider reintroducing the Zend Framework into Magento 2.4.6.
Use Composer to install the Zend Framework by running the following command:
composer require magento/zendframework1
Note: Reintroducing the Zend Framework should be approached with caution, as it may introduce additional maintenance and compatibility challenges.
Conclusion
In conclusion, the “Class Zend Not Found” error indicates the absence of the Zend framework in your Magento installation. To resolve this issue, you can choose between two methods: updating the codebase and modules to use Laminas classes or reintroducing the Zend Framework into Magento 2.4.6.
Additionally, seeking guidance from a Magento developer or expert can greatly assist you in resolving this error effectively.
By implementing the suggested methods and seeking expert assistance when needed, you can overcome the “Class Zend Not Found” error and ensure the smooth functioning of your Magento.