FluidTYPO3 / vhs

TYPO3 extension VHS: Fluid ViewHelpers
https://fluidtypo3.org
Other
190 stars 229 forks source link

v:condition.string.contains: PHP Runtime Deprecation Notice #1744

Closed Geddo closed 2 years ago

Geddo commented 2 years ago

Setup:

Example: `

yo no ` **Expection:** Needle is found as it is in haystack **Result:** `PHP Runtime Deprecation Notice: strpos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in /var/www/html/public/typo3conf/ext/vhs/Classes/ViewHelpers/Condition/String/ContainsViewHelper.php line 37`
Geddo commented 2 years ago

Converting needle and haystack explizit to strings (via -> v:variable.convert(type: 'string')) works in this case :-)

seirerman commented 2 years ago

I had the same error after upgrading to PHP 7.4 (TYPO3 9.5.32, vhs 6.0.5).

Your workaround works only if the haystack is a single number: <v:condition.string.contains haystack="176 -> v:variable.convert(type: 'string')" needle="176 -> v:variable.convert(type: 'string')">176 found!</v:condition.string.contains>

There's no output if the haystack is a list of numbers, at least for me: <v:condition.string.contains haystack="177,178,179,180,181,182,183" needle="180 -> v:variable.convert(type: 'string')">180 found!</v:condition.string.contains> The error message is gone, though.

I also think this should be fixed in vhs and not by using a vhs viewhelper to fix another vhs viewhelper. ;-) Would you mind reopening the issue again?

seirerman commented 2 years ago

I was also able use another workaround to make it work again: By adding another comma to the ID list and changing the needle to "ID," both haystack and needle are already strings, and v:variable:convert isn't needed at all. This would also work if I'm looking for the last ID.

<v:condition.string.contains haystack="177,178,179,180,181,182,183," needle="180,">