Bug #85604
closedPHP warning when doing math in Fluid
0%
Description
The following causes a PHP warning in fluid in TYPO3 8 and 9 with PHP 7.1.
<f:variable name="total" value="12" /> <f:variable name="done" value="3" /> {total - done}
PHP Warning: A non-numeric value encountered in ...../typo3_src-8.7.17/vendor/typo3fluid/fluid/src/Core/Parser/SyntaxTree/Expression/MathExpressionNode.php line 75
It looks like the variables are passed as string. They should be cast to int or float.
Updated by Thomas Luzat over 6 years ago
Rudy Gnodde wrote:
It looks like the variables are passed as string. They should be cast to int or float.
Did you confirm that it's "12" and "3"? I think this may be related to this bug report/cause:
https://github.com/TYPO3/Fluid/issues/300
Which is probably fixed in:
https://github.com/TYPO3/Fluid/commit/5b6d5d3a48f4ea9e386a0584336801899d1d16f4
This does of course require a Fluid update to arrive in TYPO3, but can be installed from Git in a composer-based install or by manually applying that patch for testing.
Updated by Rudy Gnodde over 6 years ago
Yes, it was "12" and "3". I don't have access to an environment with PHP 7.1 at the moment, but I can test the patch tonight or tomorrow night.
Updated by Susanne Moog about 6 years ago
- Status changed from New to Needs Feedback
Did you test the patch / newer fluid version? this should be fixed.
Updated by Wouter Wolters about 6 years ago
- Has duplicate Bug #85741: Bugfix for MathExpressionNode.php added
Updated by Riccardo De Contardi almost 6 years ago
- Status changed from Needs Feedback to Closed
No feedback since the last 90 days => closing this issue.
If you think that this is the wrong decision or experience the issue again and have more information about how to reproduce your problem, please reopen it or open a new issue with a reference to this one.
Thank you and best regards
Updated by Daxboeck no-lastname-given over 5 years ago
Dear Gentlemen,
I presented this fix quite a while ago and instead of incorporating it, you just closed the issue without any change in the core ?
Seriously ?
MathExpressionNode.php lacks type declarations and here is my proposed fix to avoid unnecessary warnings:
/**
* @param integer|float $left
* @param string $operator
* @param integer|float $right
* @return integer|float
*/
protected static function evaluateOperation($left, $operator, $right)
{
if ($operator === '%') {
return (float)$left % (float)$right;
} elseif ($operator === '-') {
return (float)$left - (float)$right;
} elseif ($operator === '+') {
return (float)$left + (float)$right;
} elseif ($operator === '*') {
return (float)$left * (float)$right;
} elseif ($operator === '/') {
return (integer) $right !== 0 ? (float)$left / (float)$right : 0;
} elseif ($operator === '^') {
return pow((float)$left, (float)$right);
}
return 0;
}
Can you please include the easy fix in MathExpressionNode.php ?
Best regards,
Patrick
Updated by Benni Mack over 5 years ago
Hi Patrick,
apparently this was fixed in Fluid Standalone (which is a separate TYPO3 project and maintained here https://github.com/TYPO3/Fluid/) last year - as suggested, I would like to know if Fluid Standalone 2.6.0 fixes this issue?
Updated by Oliver Hader over 5 years ago
- Has duplicate Bug #87978: Missing declarations in MathExpressionNode.php added