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

Also available in: Atom PDF