Project

General

Profile

Actions

Bug #85604

closed

PHP warning when doing math in Fluid

Added by Rudy Gnodde over 5 years ago. Updated about 5 years ago.

Status:
Closed
Priority:
Should have
Assignee:
-
Category:
Fluid
Target version:
-
Start date:
2018-07-20
Due date:
% Done:

0%

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

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.


Related issues 2 (0 open2 closed)

Has duplicate TYPO3 Core - Bug #85741: Bugfix for MathExpressionNode.phpClosed2018-08-03

Actions
Has duplicate TYPO3 Core - Bug #87978: Missing declarations in MathExpressionNode.phpClosed2019-03-22

Actions
Actions #1

Updated by Thomas Luzat over 5 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.

Actions #2

Updated by Rudy Gnodde over 5 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.

Actions #3

Updated by Susanne Moog over 5 years ago

  • Status changed from New to Needs Feedback

Did you test the patch / newer fluid version? this should be fixed.

Actions #4

Updated by Wouter Wolters over 5 years ago

  • Has duplicate Bug #85741: Bugfix for MathExpressionNode.php added
Actions #5

Updated by Riccardo De Contardi about 5 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

Actions #6

Updated by Daxboeck no-lastname-given about 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

Actions #7

Updated by Benni Mack about 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?

Actions #8

Updated by Oliver Hader about 5 years ago

  • Has duplicate Bug #87978: Missing declarations in MathExpressionNode.php added
Actions

Also available in: Atom PDF