magento2: Error 500 when `design/header/welcome` is null

Preconditions and environment

  • Magento version: 2.4.6 (upgrading from 2.4.5-p1)
  • PHP 8.1

Steps to reproduce

  • The config design/header/welcome is null

Expected result

  • Nothing special, just not crashing.

Actual result

Error 500, with exception when accessing the frontend:

TypeError: addslashes(): Argument #1 ($string) must be of type string, null given in /var/www/html/app/vendor/magento/framework/Escaper.php:440

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

WORKAROUND

If anyone stumbles upon the same issue : Set a value to the field in Content > Configuration > pick your scope > Header welcome text and you are good to go.

image

Release note

No response

Triage and priority

  • Severity: S0 - Affects critical data or functionality and leaves users without workaround.
  • Severity: S1 - Affects critical data or functionality and forces users to employ a workaround.
  • Severity: S2 - Affects non-critical data or functionality and forces users to employ a workaround.
  • Severity: S3 - Affects non-critical data or functionality and does not force users to employ a workaround.
  • Severity: S4 - Affects aesthetics, professional look and feel, “quality” or “usability”.

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 5
  • Comments: 25 (7 by maintainers)

Most upvoted comments

I’ve created a pull request to solve this issue and it was approved yesterday. You can apply this patch to your project:

From 5223d7e9c911f3a19a7ed42b28127b2a1afe7e1d Mon Sep 17 00:00:00 2001
From: Tu Van <vandinhtuit@gmail.com>
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
             );

Document on how to apply a composer patch:

Pull request: #37222

That’s correct, the fix will be included in 2.4.7 (to be released in about 2 weeks)

After a git bisect session, I’ve found the fix in core magento for this: https://github.com/magento/magento2/commit/4b5c1dc1382c2e6e144789c49db27c9085146551

@Viper9x: it looks like your PR is no longer necessary.

I am working on this

I used your commit earlier to apply the fix, which worked well. Thanks.

@magento I am working on this

Good catch @hostep . Thanks. I’ll close my PR.

Although the purpose of that commit (https://github.com/magento/magento2/commit/4b5c1dc1382c2e6e144789c49db27c9085146551) was to fix the welcome message containing 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

Thank you to everyone involved 😃

Hi @gorghoa ,

Issue confirmed !

Verified the issue in 2.4.6 Instance and 2.4-Develop instance.The issue is reproducible in 2.4.6,But not reproducible in 2.4-develop instance.

We can reproduce the issue in 2.4.6 Magento instance,Hence we are confirming the issue.

Preconditions: Magento Version 2.4.6 and 2.4-develop PHP Version 8.1

1.The issue is not reproducible with 2.4-develop instance

Kindly refer the below screenshots:

fr3 fr4

Steps to reproduce:

  • Install Magento instance 2.4 - develop
  • Go to Admin Panel and click the content option
  • Select Configuration option under Design
  • Click the edit button of Main website store view
  • Click the header option and Select the Welcome text box
  • Delete the default welcome message and save the configuration
  • Go to front end hit the url.

In 2.4-develop instance when we are accessing the front end url with default welcome Message as null,its working without any issue,Without welcome msg front end running properly.So the issue is not reproducible in 2.4-develop.

2.But The issue is reproducible in 2.4.6

Kindly refer the below screenshots:

fr2 fr1

Steps to reproduce:

  • Install Magento instance 2.4.6
  • Go to Admin Panel and click the content option
  • Select Configuration option under Design
  • Click the edit button of Main website store view
  • Click the header option and Select the Welcome text box
  • Delete the default welcome message and save the configuration
  • Go to front end hit the url.

When we accessing the front with default welcome message as null,Its showing error with exception as per actual result and this is reproducible in 2.4.6 magento instance,Hence we are confirming the issue.

Regards,