Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed null parameter warning in Mage_Wishlist_Controller_Abstract::allcartAction() #4083

Merged
merged 3 commits into from
Jul 7, 2024

Conversation

addison74
Copy link
Contributor

@addison74 addison74 commented Jul 4, 2024

This PR is related to the issue #4076.

I am getting this error with PHP > 8.1 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 374 kB as size and inside the same line 1745 times. Every line is for a product which is not in the wishlist. With a script someone could make the system.log file as big as he wants, an pretty fast.

IMPORTANT NOTE
This PR has 4 implementations inside (4 lines - 1 my choice, 3 commented), there may be others. Please share your opinions, at the end there will be only one line left. Once it is merged I will fix the same issue in the Import/Export module.

array_filter($VARIABLE, fn ($tmpString) => strlen($tmpString ?? ''))
// $qtys = array_filter($VARIABLE, function ($tmpString) { return strlen($tmpString ?? ''); });
// $qtys = array_filter($VARIABLE, function ($tmpString) { return $tmpString !== NULL && strlen($tmpString); }); => From Drupal Community
// $qtys = @array_filter($VARIABLE, '\strlen');

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 374 kB as size and inside the same line 1745 times.

IMPORTANT NOTE: 
This PR has 3 implementations inside (3 lines, 2 commented), there may be others. Please share your opinions, at the end there will be only one line left.
@github-actions github-actions bot added the Component: Wishlist Relates to Mage_Wishlist label Jul 4, 2024
addison74 added a commit that referenced this pull request Jul 6, 2024
This PR is similar to #4083. It replaces the callback function '\strlen' with an arrow function (introduced in PHP 7.4) to avoid the error message bellow starting with PHP >8.1

Deprecated functionality: strlen(): Passing null to parameter #1
Copy link
Contributor

@fballiano fballiano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tested, works perfectly

@fballiano fballiano changed the title Deprecated functionality: strlen(): Passing null to parameter #1 Fixed null parameter warning in Mage_Wishlist_Controller_Abstract::allcartAction() Jul 7, 2024
@fballiano fballiano merged commit 1382aea into main Jul 7, 2024
31 checks passed
@fballiano fballiano deleted the ADDISON74-strlen branch July 7, 2024 19:28
@fballiano fballiano restored the ADDISON74-strlen branch July 7, 2024 19:28
@fballiano fballiano deleted the ADDISON74-strlen branch July 7, 2024 19:28
@sreichel
Copy link
Contributor

On phpstan level 5 ...


Line Controller/Abstract.php


88 Parameter #2 $callback of function array_filter expects (callable(mixed): bool)|null, Closure(mixed): int<0, max> given.


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Wishlist Relates to Mage_Wishlist
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Deprecated functionality: strlen(): Passing null to parameter #1 - Abstract.php
4 participants