Unsupported operand types: string + int

aksmith

Member

I am running Fabrik on a J4 site with about 15 lists/forms migrated from J3. The two most complex forms/lists (many related tables, casc dropdowns, db joins etc) were throwing a fatal error (simpler forms are fine):

Unsupported operand types: string + int

Along with item not found etc.
Debugging led to:


/libraries/fabrik/fabrik/fabrik/Helpers/Php.php line 69:

private static function createFunctionInMemory($string)
{
eval($string);
}

I changed eval to intval and the problem is solved - I think.

I have not had time to fully test the forms.
The more simple lists seem fine.

Should i post this issue on Github?
Many thanks to all who have helped the Fabrik J4 project!
Best regards,
Alan
 
Should i post this issue on Github?
No, there's no GitHub for F4, this forum is the correct place.

This function is running your custom php code. So check your code.
I assume you are trying to add an empty string to something. In php8 '' is a string and not cast to 0 as before.
 
Yup - using intval wrecks the admin view filter options, select lists etc.
Checking custom code - so far I cannot find any empty strings...
 
Changed back to intval so I could load the form with fabrikdebug.
See screenshot - any ideas on tracking down the 2 bad parameters would be greatly appreciated!
I am wondering if a join returns a null vaue (missing data or wrong data type) could be the issue,
 

Attachments

  • Screenshot 2024-01-16 at 10.20.06 AM.png
    Screenshot 2024-01-16 at 10.20.06 AM.png
    329.6 KB · Views: 52
These are only deprecated messages, not breaking anything at the moment.
But yes, in php7 null/''/0 didn't matter but has to be fixed now.

I cannot find any empty strings
It may be a variable containing an empty string or null, e.g. a rowid in a new record.
So cast to int before using it with +.
 
I am running a calc field with this code:
$nextWeek = '{sul4t_newcardsame___currentWeek}' + 1;
return $nextWeek;

currentWeek field is dbjoin from another table that is a VARCHAR - so I am wondering if that data gets pulled in as a string (even though it's always integers). So maybe change the field type in the other table to INT?
 
So maybe change the field type in the other table to INT?
No, just use the correct php code.

Obviously '{sul4t_newcardsame___currentWeek}' is a string.
And it is empty (or not numeric) at one point of calculation (calc elements may be run several times in a form).
You can always dump your variables with var_dump(); for debugging.
You may also consider to use ...currentWeek_raw}, depending on your element settings the non-raw element can e.g. be a link to details etc.

Do $nextWeek =(int) '{sul4t_newcardsame___currentWeek}' + 1;
to force it to int (php8 doesn't do it any longer automatically) or fetch a non-numeric string in another way.
 
Last edited:
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top