Project

General

Profile

Actions

Bug #90786

closed

NumberViewHelper: Avoid PHP Warning with (empty) string

Added by Frank Frewer about 4 years ago. Updated about 4 years ago.

Status:
Closed
Priority:
Should have
Assignee:
-
Category:
Fluid
Target version:
-
Start date:
2020-03-19
Due date:
% Done:

100%

Estimated time:
TYPO3 Version:
10
PHP Version:
Tags:
Complexity:
Is Regression:
Sprint Focus:

Description

From NumberViewHelper:

        $stringToFormat = $renderChildrenClosure();
        return number_format($stringToFormat, $decimals, $decimalSeparator, $thousandsSeparator);

If $stringToFormat is an empty string, number_format will produce a PHP Warning, as it expects the first parameter to be a float value (and not a string).

In my opinion the naming of the variable inside the number_format call is already misleading: $floatToFormat should make it clearer.

I don't know if it is intentional that an empty string or a string which is not a number produces a PHP Warning, to let the template developer ensure that there is a number.

If not, why not passing the number_format and gives back the unformatted string, e.g. in this - not tested - way:

        $stringToFormat = (string)$renderChildrenClosure();
        $floatToFormat = (float)$stringToFormat;
        if ($stringToFormat === '' || ($stringToFormat !== '0' && $floatToFormat === 0)) {
            return $stringToFormat;
        }
        return number_format($floatToFormat, $decimals, $decimalSeparator, $thousandsSeparator);
Actions #1

Updated by Gerrit Code Review about 4 years ago

  • Status changed from New to Under Review

Patch set 1 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/63798

Actions #2

Updated by Gerrit Code Review about 4 years ago

Patch set 2 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/63798

Actions #3

Updated by Gerrit Code Review about 4 years ago

Patch set 1 for branch 9.5 of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/63776

Actions #4

Updated by Susanne Moog about 4 years ago

  • Status changed from Under Review to Resolved
  • % Done changed from 0 to 100
Actions #5

Updated by Benni Mack about 4 years ago

  • Status changed from Resolved to Closed
Actions

Also available in: Atom PDF