Deprecated Functionality: strip_tags(): Passing null to parameter #1

Deprecated Functionality Passing null to parameter #1

While upgrading to Magento 2.4.6, you may face this error often.

Exception #0 (Exception): Deprecated Functionality: strip_tags(): Passing null to parameter #1 ($string) of type string is deprecated.

From PHP 8.1, some functions like strip_tags(), htmlspecialchars(), mb_strtolower(), and trim() functions throw errors when you try to pass a null value to the function’s parameters.

The quick fix in most cases is to use the null coalescing operator to provide a default value as appropriate, so you don’t need a long null check around every use. For instance, htmlspecialchars($something) can be replaced with htmlspecialchars($mystring ?? ”)

Depending on your case, you may be able to just fix them manually a few at a time, either adding ?? ” or fixing a logic bug where you weren’t expecting a null anyway.

Examples :

Let me know any other functions that caused issues in upgrading your project.

Happy Upgrading 🙂

You may also like

How to Use ViewModel in Magento 2: A Simple Guide

Magento 2: How to use helper in PHTML?

How to Remove Sample Data from Magento 2

Create CMS Block Programmatically Magento 2

Leave a Reply

Your email address will not be published. Required fields are marked *