[2024-09-19T07:06:49.757455+00:00] main.CRITICAL: Exception: Deprecated Functionality: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /var/www/html/magento2/vendor/magento/zend-db/library/Zend/Db/Adapter/Abstract.php on line 1044 in /var/www/html/magento2/vendor/magento/framework/App/ErrorHandler.php:62
I'm running all the software versions stated in the installation instructions listed in the system requirements.
Is this a common issue with this version?
Hello @stevenlrug275e
That error indicates somewhere in your code passing null to the third parameter when calling a PHP function that is deprecated in PHP 8.1.
For example,
$method = null;
str_replace('methods_', '', $method)
TO
str_replace('methods_', '', $method ?? '');
The type of the third parameter should be changed to string if it is null.
Hope it helps !
If you find our reply helpful, please give us kudos.
A Leading Magento Development Agency That Delivers Powerful Results, Innovation, and Secure Digital Transformation.
WebDesk Solution Support Team
Get a Free Quote | | Adobe Commerce Partner | Hire Us | Call Us 877.536.3789
Thank You,
WebDesk Solution Support Team
Get a Free Quote | Email | Adobe Commerce Partner | Hire Us | Call Us 877.536.3789
Location: 150 King St. W. Toronto, ON M5H 1J9
Hello @stevenlrug275e,
This issue occurs when str_replace is being passed a null value in your code. To identify which module is causing this, you can use the following command to search for the str_replace function in your custom module and Theme:
Command:
grep -r "str_replace"
Run this in command prompt in your app/code or app/design directory, and then review the file where it's used. Ensure that you check whether the variable being passed has a value before applying the str_replace function. If necessary, add a validation check for the variable before using str_replace.
If you are in developer mode, you should be able to see the full stack trace on the var/log/debug.log file.
If you don't find it there, you might resolve to go into the vendor/magento/framework/App/ErrorHandler.php and on the beginning of the function (line function 47) add a debug_print_backtrace(); to get the full stack trace on the error. This way you can see where this is been triggered and reach to the correct location to fix.
Make sure you have the error reporting set correctly on your php configuration so you can see the error on the browser.
If you find str_replace function to pass the null data then you can put like this:
str_replace($data ?? ' ']);
this should solve deprecated functionality problem and checkout will run smoothly.
If the issue will be resolved, Click Kudos & Accept as a Solution.
Yes, I understand that I can find the STR calls and replace them. however, I'm most wondering why I'm having this issue on a fresh install of magento when Magento should have already had these updates done?
This just doesn't seem right.
I just did another fresh install and am still having this same issue wihtout any addition themes or modules installed. This s just a bare basic 2.4.7 install which is supposed to have php8.1+ support.
How is this happening? Is magento not an operating solution out of the box?
In Magento 2.4.7 with PHP 8.1, the str_replace function can be used to replace substrings in strings, but developers must ensure compatibility with PHP 8.1's strict typing and deprecated functions.