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_Shipping_Model_Resource_Carrier_Tablerate #4073

Merged
merged 3 commits into from
Jul 4, 2024

Conversation

addison74
Copy link
Contributor

In order to reproduce this issue use a table rate (uploading a CSV file in the Backend) in your test environment then follow the checkout steps to the end.

Starting with PHP 8.1 to 8.3 you will get this error in the OM log file.

Deprecated functionality: strlen(): Passing null to parameter #1 ($string) of type string is deprecated  in /var/www/html/app/code/core/Mage/Shipping/Model/Resource/Carrier/Tablerate.php on line 131

My approach is using strlen($variable ?? '') but it could be strlen((string) $variabile) too. Please feel free to share your opinion for the best implementation.

In order to reproduce this issue use a table rate in your test environment then follow the checkout steps to the end. Starting with PHP 8.1 to 8.3 you will get this error in the OM log file.

```
Deprecated functionality: strlen(): Passing null to parameter #1 ($string) of type string is deprecated  in /var/www/html/app/code/core/Mage/Shipping/Model/Resource/Carrier/Tablerate.php on line 131
```

My approach is using strlen($variable ?? '') but it could be strlen((string) $variabile) too. I am open to opinions.
@github-actions github-actions bot added the Component: Shipping Relates to Mage_Shipping label Jul 3, 2024
@addison74 addison74 linked an issue Jul 3, 2024 that may be closed by this pull request
Comment on lines 130 to 131
$postcode = $request->getDestPostcode();
while (strlen($postcode) > 1) {
while (strlen($postcode ?? '') > 1) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
$postcode = $request->getDestPostcode();
while (strlen($postcode) > 1) {
while (strlen($postcode ?? '') > 1) {
$postcode = (string)$request->getDestPostcode();
while (strlen($postcode) > 1) {

It's more efficient as it's outside the loop.

Copy link
Contributor

Choose a reason for hiding this comment

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

good catch @addison74, I like @kiatng version, it looks neater to me because it doesn't get executed inside the loop

@fballiano fballiano changed the title Deprecated functionality: strlen() in the Tablerate.php file Fixed null parameter warning in Mage_Shipping_Model_Resource_Carrier_Tablerate Jul 4, 2024
@fballiano fballiano merged commit 2b907ad into main Jul 4, 2024
31 checks passed
@fballiano fballiano deleted the ADDISON74-tablerate-error branch July 4, 2024 11:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Shipping Relates to Mage_Shipping
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Deprecated functionality: strlen(): Passing null to parameter #1
3 participants