PHP8 error with calc plugin

BasilC

Member
I downloaded the Github zip that was current about ten days ago and installed it on a website. Today I tried switching the website to PHP8, but have run into a problem with the calc element.

Error messages:

Unsupported operand types: string + string
/plugins/fabrik_element/calc/calc.php(105) : eval()'d code:1

Unsupported operand types: string + string
/plugins/fabrik_element/calc/calc.php(315) : eval()'d code:1

number_format(): Argument #1 ($num) must be of type float, string given
plugins/fabrik_element/calc/calc.php(105) : eval()'d code:2

Reverted to PHP7.4 and it runs OK again.

Checked my calc.php against the version in Github and they are identical.

Is this an issue with calc.php or with what I've entered in the calc element for that table?
 
or with what I've entered in the calc element for that table?
In this case it seems to be your custom calc code not to be approriate for php8.
"Unsupported operand types: string + string
/plugins/fabrik_element/calc/calc.php(105) : eval()'d code:1"
looks like you are doing things like '1' + '2'
 
Guilty as charged, I was adding two strings. And on the next line I was using number_format() on a string.

So now, after some googling (actually using Ecosia) I've filled in a little bit of the huge gap in my knowledge of PHP and discovered how to cast variable types.

What's more, it turned out that adding those two variables together was redundant because the second variable is no longer used (a membership application form where originally two people from the same address could use the same form was changed to one person per form).

$total = '{join_u3a___person1_fees_raw}' + '{join_u3a___person2_fees_raw}';
$total = number_format($total, 2);
return '<b>£' . $total . '</b>';

works in PHP7.4 but not in PHP8. Now changed to

$total = (float) '{join_u3a___person1_fees_raw}';
$total = number_format($total, 2);
return '<b>£' . $total . '</b>';
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top