Closed ADDISON74 closed 15 hours ago
This is before Magento 1.8.1.0
$qtys = $this->getRequest()->getParam('qty');
This is after Magento 1.8.1.0
$qtysString = $this->getRequest()->getParam('qty');
$qtys = array_filter(json_decode($qtysString), 'strlen');
This PR #2335 changed strlen to \strlen. I don't know what was its scope.
$qtys = array_filter(json_decode($qtysString), '\strlen');
Before PHP 8.1 this line would remove empty values from an array like null, false, '', but 0 and '0' will be kept. Starting with PHP 8.1 a deprecated error is issued as I mentioned in the initial report. After doing a research on the Internet, there are a few implementations to solve this issue:
This one is readable
$qtys = array_filter(json_decode($qtysString), function ($qtysString) { return strlen($qtysString ?? ''); });
A shorter version
$qtys = array_filter(json_decode($qtysString), fn($qtysString) => strlen($qtysString ?? ''));
Suppress the warning with @
$qtys = @array_filter(json_decode($qtysString), '\strlen');
I would like to get some feedback which implementation should be used.
Please note there is another file with this issue
arrow functions became available in php7.4 so all and all I think I like the shorter version :-)
Fixed in #4083.
I am getting this error with PHP 8.3 in the system.log file:
Deprecated functionality: strlen(): Passing null to parameter #1 ($string) of type string is deprecated in /var/www/html/app/code/core/Mage/Wishlist/Controller/Abstract.php on line 88
/app/code/core/Mage/Wishlist/Controller/Abstract.php on line 88
In order to reproduce this issue log into a customer account in the Frontend then add any product to the Wishlist. You will be redirected to the customer account. A part of the URL is wishlist/index/index/wishlist_id/[PRODUCT_ID]/. Press the [Add All to the Cart] button. In my case I am getting an error message because the product has custom options and I have to choose them. If you take a look into the /var/log directory you will see a nice system.log file, having 371 kB as size and inside the same line 1745 times.