Bug #85604
closed
PHP warning when doing math in Fluid
Added by Rudy Gnodde almost 6 years ago.
Updated about 5 years ago.
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.
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.
- Status changed from New to Needs Feedback
Did you test the patch / newer fluid version? this should be fixed.
- Has duplicate Bug #85741: Bugfix for MathExpressionNode.php added
- 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
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
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?
- Has duplicate Bug #87978: Missing declarations in MathExpressionNode.php added
Also available in: Atom
PDF