Fixed Deprecated exception when using trim filter in PHP 8.1

pegasus

Well-known member
@XF Bug Bot, I should point out that XF\Template\Templater::fnTrim also sometimes throws this message because the method does not ensure that the incoming template text in $str has been cast to string (occasionally a {$...|raw} may not have been passed, may be an integer, etc).

The new method should be:
Code:
	public function fnTrim($templater, &$escape, $str, $charlist = " \t\n\r\0\x0B")
	{
		$str = (string)$str;
		return trim($str, $charlist);
	}
Also, in XF\Template\Compiler\Trim, it should call $templater->fnTrim and not trim directly, or if the escaping is a problem, XF\Templater\Compiler\Trim should also make sure that $valueHtml is cast:
Code:
return "trim((string){$valueHtml})";
 
Last edited:
For future reference please always create a new bug report.

The bug bot account isn’t monitored and this may have gone unnoticed had I not viewed the original thread you posted in.
 
Thank you for reporting this issue, it has now been resolved. We are aiming to include any changes that have been made in a future XF release (2.2.9).

Change log:
Improve PHP 8.1 compatibility in template trim tag/function
There may be a delay before changes are rolled out to the XenForo Community.
 
Top Bottom