1

Recently I have upgraded my adobe commerce from 2.4.4. to 2.4.6. I am using PHP 8.1. After upgrading my forntend throws a exception error.

[2023-03-16T06:03:15.101913+00:00] report.CRITICAL: TypeError: addslashes(): Argument #1 ($string) must be of type string, null given in /app/vendor/magento/framework/Escaper.php:440
Stack trace:
#0 /app/vendor/magento/framework/Escaper.php(440): addslashes(NULL)
#1 /app/vendor/magento/module-theme/Block/Html/Header.php(62): Magento\Framework\Escaper->escapeQuote(NULL, true)
#2 /app/vendor/magento/module-theme/view/frontend/templates/html/header.phtml(11): Magento\Theme\Block\Html\Header->getWelcome()
#3 /app/vendor/magento/framework/View/TemplateEngine/Php.php(71): include('/app/vendor/mag...')
#4 /app/vendor/magento/framework/View/Element/Template.php(263): Magento\Framework\View\TemplateEngine\Php->render(Object(Magento\Theme\Block\Html\Header), '/app/vendor/mag...', Array)
#5 /app/vendor/magento/framework/View/Element/Template.php(293): Magento\Framework\View\Element\Template->fetchView('/app/vendor/mag...')
#6 /app/vendor/magento/framework/View/Element/AbstractBlock.php(1095): Magento\Framework\View\Element\Template->_toHtml()
#7 /app/vendor/magento/framework/View/Element/AbstractBlock.php(1099): Magento\Framework\View\Element\AbstractBlock->Magento\Framework\View\Element\{closure}()
#8 /app/vendor/magento/framework/View/Element/AbstractBlock.php(660): Magento\Framework\View\Element\AbstractBlock->_loadCache()
#9 /app/vendor/magento/framework/View/Layout.php(578): Magento\Framework\View\Element\AbstractBlock->toHtml()
#10 /app/vendor/magento/framework/View/Layout.php(555): Magento\Framework\View\Layout->_renderBlock('header')
#11 /app/vendor/magento/framework/View/Layout.php(510): Magento\Framework\View\Layout->renderNonCachedElement('header')
#12 /app/vendor/magento/framework/View/Element/Html/Links.php(63): Magento\Framework\View\Layout->renderElement('header')
#13 /app/vendor/magento/framework/View/Element/Html/Links.php(83): Magento\Framework\View\Element\Html\Links->renderLink(Object(Magento\Theme\Block\Html\Header))
#14 /app/vendor/magento/framework/View/Element/AbstractBlock.php(1095): Magento\Framework\View\Element\Html\Links->_toHtml()
#15 /app/vendor/magento/framework/View/Element/AbstractBlock.php(1099): Magento\Framework\View\Element\AbstractBlock->Magento\Framework\View\Element\{closure}()
#16 /app/vendor/magento/framework/View/Element/AbstractBlock.php(660): Magento\Framework\View\Element\AbstractBlock->_loadCache()
#17 /app/vendor/magento/framework/View/Layout.php(578): Magento\Framework\View\Element\AbstractBlock->toHtml()
#18 /app/vendor/magento/framework/View/Layout.php(555): Magento\Framework\View\Layout->_renderBlock('header.links')
#19 /app/vendor/magento/framework/View/Layout.php(510): Magento\Framework\View\Layout->renderNonCachedElement('header.links')
#20 /app/vendor/magento/framework/View/Layout.php(606): Magento\Framework\View\Layout->renderElement('header.links', false)
#21 /app/vendor/magento/framework/View/Layout.php(557): Magento\Framework\View\Layout->_renderContainer('header.panel', false)
#22 /app/vendor/magento/framework/View/Layout.php(510): Magento\Framework\View\Layout->renderNonCachedElement('header.panel')
#23 /app/vendor/magento/framework/View/Layout.php(606): Magento\Framework\View\Layout->renderElement('header.panel', false)
#24 /app/vendor/magento/framework/View/Layout.php(557): Magento\Framework\View\Layout->_renderContainer('header.panel.wr...', false)
#25 /app/vendor/magento/framework/View/Layout.php(510): Magento\Framework\View\Layout->renderNonCachedElement('header.panel.wr...')
#26 /app/vendor/magento/framework/View/Layout.php(606): Magento\Framework\View\Layout->renderElement('header.panel.wr...', false)
#27 /app/vendor/magento/framework/View/Layout.php(557): Magento\Framework\View\Layout->_renderContainer('header.containe...', false)
#28 /app/vendor/magento/framework/View/Layout.php(510): Magento\Framework\View\Layout->renderNonCachedElement('header.containe...')
#29 /app/vendor/magento/framework/View/Layout.php(606): Magento\Framework\View\Layout->renderElement('header.containe...', false)
#30 /app/vendor/magento/framework/View/Layout.php(557): Magento\Framework\View\Layout->_renderContainer('header.containe...', false)
#31 /app/vendor/magento/framework/View/Layout.php(510): Magento\Framework\View\Layout->renderNonCachedElement('header.containe...')
#32 /app/vendor/magento/framework/View/Layout.php(606): Magento\Framework\View\Layout->renderElement('header.containe...', false)
#33 /app/vendor/magento/framework/View/Layout.php(557): Magento\Framework\View\Layout->_renderContainer('page.wrapper', false)
#34 /app/vendor/magento/framework/View/Layout.php(510): Magento\Framework\View\Layout->renderNonCachedElement('page.wrapper')
#35 /app/vendor/magento/framework/View/Layout.php(606): Magento\Framework\View\Layout->renderElement('page.wrapper', false)
#36 /app/vendor/magento/framework/View/Layout.php(557): Magento\Framework\View\Layout->_renderContainer('root', false)
#37 /app/vendor/magento/framework/View/Layout.php(510): Magento\Framework\View\Layout->renderNonCachedElement('root')
#38 /app/vendor/magento/framework/View/Layout.php(975): Magento\Framework\View\Layout->renderElement('root')
#39 /app/vendor/magento/framework/Interception/Interceptor.php(58): Magento\Framework\View\Layout->getOutput()
#40 /app/vendor/magento/framework/Interception/Interceptor.php(138): Magento\Framework\View\Layout\Interceptor->___callParent('getOutput', Array)
#41 /app/vendor/magento/framework/Interception/Interceptor.php(153): Magento\Framework\View\Layout\Interceptor->Magento\Framework\Interception\{closure}()
#42 /app/generated/code/Magento/Framework/View/Layout/Interceptor.php(50): Magento\Framework\View\Layout\Interceptor->___callPlugins('getOutput', Array, Array)
#43 /app/vendor/magento/framework/View/Result/Page.php(260): Magento\Framework\View\Layout\Interceptor->getOutput()
#44 /app/vendor/magento/framework/View/Result/Layout.php(171): Magento\Framework\View\Result\Page->render(Object(Magento\Framework\App\Response\Http\Interceptor))
#45 /app/vendor/magento/framework/Interception/Interceptor.php(58): Magento\Framework\View\Result\Layout->renderResult(Object(Magento\Framework\App\Response\Http\Interceptor))
#46 /app/vendor/magento/framework/Interception/Interceptor.php(138): Magento\Framework\View\Result\Page\Interceptor->___callParent('renderResult', Array)
#47 /app/vendor/magento/framework/Interception/Interceptor.php(153): Magento\Framework\View\Result\Page\Interceptor->Magento\Framework\Interception\{closure}(Object(Magento\Framework\App\Response\Http\Interceptor))
#48 /app/generated/code/Magento/Framework/View/Result/Page/Interceptor.php(41): Magento\Framework\View\Result\Page\Interceptor->___callPlugins('renderResult', Array, Array)
#49 /app/vendor/magento/framework/App/Http.php(120): Magento\Framework\View\Result\Page\Interceptor->renderResult(Object(Magento\Framework\App\Response\Http\Interceptor))
#50 /app/vendor/magento/framework/App/Bootstrap.php(264): Magento\Framework\App\Http->launch()
#51 /app/pub/index.php(30): Magento\Framework\App\Bootstrap->run(Object(Magento\Framework\App\Http\Interceptor))

Thanks in advance.

2
  • Magento 2.4.6 must recommend PHP 8.2 so please try to jump in PHP 8.2 Mar 16, 2023 at 6:09
  • @NavneetSharma Magento 2.4.6 support for both PHP 8.2 and PHP 8.1. This issue happens on both of those PHP versions.
    – Tu Van
    Mar 16, 2023 at 7:30

3 Answers 3

9

This is a bug in Magento 2.4.6. Github issue: https://github.com/magento/magento2/issues/37208

And it was resolved by the below commit in Magento core code: https://github.com/magento/magento2/commit/4b5c1dc1382c2e6e144789c49db27c9085146551

Although the purpose of that commit was to fix another issue - "the welcome message contains single quote character", it also inadvertently solved this issue since __() method return \Magento\Framework\Phrase which also force change the type of the text to string

Based on all the changes, I've created a patch, you can use it to resolve this issue:

From 5223d7e9c911f3a19a7ed42b28127b2a1afe7e1d Mon Sep 17 00:00:00 2001
From: Tu Van <[email protected]>
Date: Thu, 16 Mar 2023 14:20:38 +0700
Subject: [PATCH] Fixed the welcome message contains single quote character

---
 vendor/magento/module-theme/Block/Html/Header.php | 3 +-
 1 file changed, 1 insertion(+), 2 deletion(-)

diff --git a/vendor/magento/module-theme/Block/Html/Header.php b/vendor/magento/module-theme/Block/Html/Header.php
index 1550ebaa367d..e7eafc0b7316 100644
--- a/vendor/magento/module-theme/Block/Html/Header.php
+++ b/vendor/magento/module-theme/Block/Html/Header.php
@@ -57,7 +57,6 @@ public function getWelcome()
                 \Magento\Store\Model\ScopeInterface::SCOPE_STORE
             );
         }
-        $this->_data['welcome'] =  $this->escaper->escapeQuote($this->_data['welcome'], true);
-        return __($this->_data['welcome']);
+        return $this->escaper->escapeQuote(__($this->_data['welcome'])->render(), true);
     }
 }

===
Old patch: (it works but we should use the new version above to apply the fix for another issue as I mentioned above)

From 5223d7e9c911f3a19a7ed42b28127b2a1afe7e1d Mon Sep 17 00:00:00 2001
From: Tu Van <[email protected]>
Date: Thu, 16 Mar 2023 14:20:38 +0700
Subject: [PATCH] Fix PHP Type error in Header block class

---
 vendor/magento/module-theme/Block/Html/Header.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/vendor/magento/module-theme/Block/Html/Header.php b/vendor/magento/module-theme/Block/Html/Header.php
index 1550ebaa367d..e7eafc0b7316 100644
--- a/vendor/magento/module-theme/Block/Html/Header.php
+++ b/vendor/magento/module-theme/Block/Html/Header.php
@@ -54,7 +54,7 @@ public function __construct(
     public function getWelcome()
     {
         if (empty($this->_data['welcome'])) {
-            $this->_data['welcome'] = $this->_scopeConfig->getValue(
+            $this->_data['welcome'] = (string)$this->_scopeConfig->getValue(
                 'design/header/welcome',
                 ScopeInterface::SCOPE_STORE
             );

2
  • tnx for the patch. It fixed my issue :)
    – Korbin
    Mar 17, 2023 at 9:55
  • @Korbin You’re welcome :)
    – Tu Van
    Mar 17, 2023 at 12:16
1

The quick fix to this magento bug is setting some welcome message. Launch this query

update core_config_data set value = "Test welcome message" where path = "design/header/welcome";
1
  • 1
    Thanks! update core_config_data set value = "" where path = "design/header/welcome"; is even better. Just can't be a null value.
    – Dragonfly
    Aug 18, 2023 at 15:56
0

I tried to upgrade 2.4.5-p1 to 2.4.6-p2 and 2.4.5-p3 to 2.4.6-p2, same error twice.

Following this page, I check on the backend that the "Welcome Text" field was empty in the Website and Store settings (in backend Content/Design/Configuration)

enter image description here

Those fields was empty because of the Default value was heradate to Website and Store.

So the solution was put the same value of "Welcome Text" field, in Default, Website and Store configuration.

enter image description here

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.