Skip to main content
ErrorsMagentoMagento 2

Magento 2 – TypeError: addslashes(): Argument #1 ($string) must be of type string upgrade error

By October 24, 2023No Comments

After updating Magento from 2.4.5-p4 to 2.4.6-p2, I hit the error;

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

The error relates to an empty welcome message and a patch is now available.

This error is only visible if the store’s Welcome Text is empty in Magento 2.4.6. A quick workaround is to add Welcome Text in Magento admin.
Content > Configuration > pick your scope > Header > Welcome Text

I used Wasim’s Stack overflow suggestion of modifying the core file. As the file is likely to be fixed in a later core release I’m happy for it to written over by a future Magento upgrade.

modify the following block class directly:

vendor\magento\module-theme\Block\Html\Header.php

Change Line #62 & 63:

$this->data[‘welcome’] = $this->escaper->escapeQuote($this->_data[‘welcome’], true); return _($this->_data[‘welcome’]);

To:

return $this->escaper->escapeQuote(__($this->_data[‘welcome’])->render(), true);

ElasticSearch and Maria DB server versions should also be upgraded in Magento 2.4.6 core upgrades, but aren’t the fix for the TypeError: addslashes(): Argument #1 ($string) must be of type string upgrade error.

Andrew Taylor

A senior UI designer with over 25 years of web design and web development experience working for some of the largest companies in the UK. An expert in all things Magento and WordPress.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.