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 passing null for number_format is deprecated for downloadable products #3340

Closed
wants to merge 1 commit into from

Conversation

kyrena
Copy link
Contributor

@kyrena kyrena commented Jun 20, 2023

Description

This fix passing null to parameter #1 ($num) of type float is deprecated for number_format with PHP 8.1/8.2.
Perhaps it's not the best way.

See also this discussion comment.

Contribution checklist

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All automated tests passed successfully (all builds are green)
  • Add yourself to contributors list

…le_Block_Adminhtml_Catalog_Product_Edit_Tab_Downloadable_Links
@github-actions github-actions bot added the Component: Downloadable Relates to Mage_Downloadable label Jun 20, 2023
@kyrena kyrena changed the title Fixed passing null for number_format is deprecated in Mage_Downloadable_Block_Adminhtml_Catalog_Product_Edit_Tab_Downloadable_Links Fixed passing null for number_format is deprecated for downloadable products Jun 20, 2023
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it better to fix it here:

public function getPriceValue($value)
{
return number_format($value, 2, null, '');

Copy link
Contributor

Choose a reason for hiding this comment

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

how would you do that? cause if $value is null I don't see what we should return

Copy link
Contributor

Choose a reason for hiding this comment

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

Ref https://onlinephp.io/c/5e8d8, when $value = null, it used to return '0.00'. Also, see the docblock:

   /**
     * Return formatted price with two digits after decimal point
     *
     * @param float $value
     * @return string
     */
    public function getPriceValue($value)
    {
       // suggestion:
        if (!$value) {
            return '0.00';
        }
        return number_format($value, 2, null, '');
    }

Note that when $value = '': we have

Fatal error: Uncaught TypeError: number_format(): Argument #1 ($num) must be of type float, string given in /home/user/scripts/code.php:3
Stack trace:
#0 /home/user/scripts/code.php(3): number_format('', 2, NULL, '')

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

Successfully merging this pull request may close these issues.

3 participants