1

I'm getting following error while compiling magento 2.4.5 which is newly upgraded from Magento 2.4.3

 Deprecated Functionality: Zend_Http_UserAgent implements the Serializable interface, which is deprecated. Implement __serialize() and __unserialize() instead (or in addition, if support for old PHP versions is necessary) in /var/www/html/wff/vendor/magento/zendframework1/library/Zend/Http/  
  UserAgent.php on line 37 

                                                                                                                      
                                                      



 report.ERROR: Deprecated Functionality: Zend_Http_UserAgent implements the Serializable interface, which is deprecated. Implement __serialize() and __unserialize() instead (or in addition, if support for old PHP versions is necessary) in /var/www/html/wff/vendor/magento/zendframework1/library/Zend/Http/UserAgent.php on line 37
#0 /var/www/html/wff/vendor/magento/zendframework1/library/Zend/Http/UserAgent.php(37): Magento\Framework\App\ErrorHandler->handler()
#1 /var/www/html/wff/vendor/composer/ClassLoader.php(480): include('...')
#2 /var/www/html/wff/vendor/composer/ClassLoader.php(346): Composer\Autoload\includeFile()
#3 [internal function]: Composer\Autoload\ClassLoader->loadClass()
#4 /var/www/html/wff/vendor/magento/framework/GetParameterClassTrait.php(34): ReflectionClass->__construct()
#5 /var/www/html/wff/vendor/magento/framework/Code/Reader/ClassReader.php(42): Magento\Framework\Code\Reader\ClassReader->getParameterClass()
#6 /var/www/html/wff/setup/src/Magento/Setup/Module/Di/Code/Reader/ClassReaderDecorator.php(35): Magento\Framework\Code\Reader\ClassReader->getConstructor()
#7 /var/www/html/wff/setup/src/Magento/Setup/Module/Di/Code/Reader/Decorator/Area.php(53): Magento\Setup\Module\Di\Code\Reader\ClassReaderDecorator->getConstructor()
#8 /var/www/html/wff/setup/src/Magento/Setup/Module/Di/App/Task/Operation/Area.php(116): Magento\Setup\Module\Di\Code\Reader\Decorator\Area->getList()
#9 /var/www/html/wff/setup/src/Magento/Setup/Module/Di/App/Task/Operation/Area.php(87): Magento\Setup\Module\Di\App\Task\Operation\Area->getDefinitionsCollection()
#10 /var/www/html/wff/setup/src/Magento/Setup/Module/Di/App/Task/Manager.php(56): Magento\Setup\Module\Di\App\Task\Operation\Area->doOperation()
#11 /var/www/html/wff/setup/src/Magento/Setup/Console/Command/DiCompileCommand.php(216): Magento\Setup\Module\Di\App\Task\Manager->process()
#12 /var/www/html/wff/vendor/symfony/console/Command/Command.php(255): Magento\Setup\Console\Command\DiCompileCommand->execute()
#13 /var/www/html/wff/vendor/symfony/console/Application.php(1021): Symfony\Component\Console\Command\Command->run()
#14 /var/www/html/wff/vendor/symfony/console/Application.php(275): Symfony\Component\Console\Application->doRunCommand()
#15 /var/www/html/wff/vendor/magento/framework/Console/Cli.php(116): Symfony\Component\Console\Application->doRun()
#16 /var/www/html/wff/vendor/symfony/console/Application.php(149): Magento\Framework\Console\Cli->doRun()
#17 /var/www/html/wff/bin/magento(23): Symfony\Component\Console\Application->run()
#18 {main} [] []

Can any one help me how to fix this php version 8.1

5
  • One of your custom modules or a 3rd-party modules (extension) caused this issue. Please add the full error here, it will allow us easier to help you more.
    – Tu Van
    Commented Jan 5, 2023 at 19:20
  • Please attach the full error. It doesn't make sense now.
    – Aaron Wang
    Commented Jan 5, 2023 at 21:45
  • @TuVan @ Wang Gang updated the question with full error this is showing on terminal after run di:compile
    – amith lal
    Commented Jan 6, 2023 at 2:33
  • Are you sure it only shows 1 to 2 lines like your post?
    – Tu Van
    Commented Jan 6, 2023 at 4:21
  • @TuVan updated the log from error log
    – amith lal
    Commented Jan 6, 2023 at 5:29

1 Answer 1

2

One of your custom modules or a 3rd-party module (extension) caused this issue.

I never get this error before but I guess a module (extension) called Zend_Http_UserAgent class which has an error as you mentioned.

To detect which file (module) caused this error, go to your Magento root directory, and run the following command:

grep -r --exclude-dir=vendor/magento/zendframework1/library/Zend/Http Zend_Http_UserAgent .

If you still need to use this module and need to use Zend_Http_UserAgent class, apply the following patch to make Zend_Http_UserAgent compatible with PHP 8.1:

Patch file to allow Zend_Http_UserAgent compatible with PHP 8.1 by Tu Van

diff --git a/vendor/magento/zendframework1/library/Zend/Http/UserAgent.php b/vendor/magento/zendframework1/library/Zend/Http/UserAgent.php
index a06402f8..17ff4490 100644
--- a/vendor/magento/zendframework1/library/Zend/Http/UserAgent.php
+++ b/vendor/magento/zendframework1/library/Zend/Http/UserAgent.php
@@ -34,7 +34,7 @@
  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  * @license    http://framework.zend.com/license/new-bsd     New BSD License
  */
-class Zend_Http_UserAgent implements Serializable
+class Zend_Http_UserAgent implements \Serializable
 {
     /**
      * 'desktop' by default if the sequence return false for each item or is empty
@@ -164,12 +164,21 @@ class Zend_Http_UserAgent implements Serializable
         }
     }

+    /**
+     * Compatible with PHP 8.1
+     *
+     * @return string
+     */
+    public function serialize() {
+        return serialize($this->__serialize());
+    }
+
     /**
      * Serialized representation of the object
      *
      * @return string
      */
-    public function serialize()
+    public function __serialize()
     {
         $device = $this->getDevice();
         $spec = array(
@@ -180,7 +189,17 @@ class Zend_Http_UserAgent implements Serializable
             'user_agent'   => $this->getServerValue('http_user_agent'),
             'http_accept'  => $this->getServerValue('http_accept'),
         );
-        return serialize($spec);
+        return $spec;
+    }
+
+    /**
+     * Compatible with PHP 8.1
+     *
+     * @param string $serialized
+     * @return void
+     */
+    public function unserialize($serialized) {
+        return $this->__unserialize($serialized);
     }

     /**
@@ -189,7 +208,7 @@ class Zend_Http_UserAgent implements Serializable
      * @param  string $serialized
      * @return void
      */
-    public function unserialize($serialized)
+    public function __unserialize($serialized)
     {
         $spec = unserialize($serialized);


Take a look at this guide to know how to apply custom patch in Magento 2: https://experienceleague.adobe.com/docs/commerce-operations/upgrade-guide/patches/apply.html

I highly recommend apply patch using Composer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.