Fixed After move to PHP 8.0: Array to string conversion src/XF.php:1143

Affected version


I just upgraded to PHP 8.0, and I get this error:

ErrorException: Template error: [E_WARNING] Array to string conversion src/XF.php:1143

#0 src/XF.php(1143): XF\Template\Templater->handleTemplateError(2, '[E_WARNING] Arr...', '/home/gaturro/p...', 1143)
#1 src/XF/Template/Templater.php(1176): XF::escapeString(Array, 'html')
#2 internal_data/code_cache/templates/l3/s1/public/PAGE_CONTAINER.php(1163): XF\Template\Templater->escape(Array)
#3 src/XF/Template/Templater.php(1626): XF\Template\Templater->{closure}(Object(XF\Template\Templater), Array, NULL)
#4 src/XF/Pub/App.php(562): XF\Template\Templater->renderTemplate('PAGE_CONTAINER', Array)
#5 src/XF/App.php(2105): XF\Pub\App->renderPageHtml('

...', Array, Object(XF\Mvc\Reply\View), Object(XF\Mvc\Renderer\Html))
#6 src/XF/Mvc/Dispatcher.php(402): XF\App->renderPage('

...', Object(XF\Mvc\Reply\View), Object(XF\Mvc\Renderer\Html))
#7 src/XF/Mvc/Dispatcher.php(58): XF\Mvc\Dispatcher->render(Object(XF\Mvc\Reply\View), 'html')
#8 src/XF/App.php(2300): XF\Mvc\Dispatcher->run()
#9 src/XF.php(488): XF\App->run()
#10 index.php(20): XF::runApp('XF\\Pub\\App')
#11 {main}

Could anyone guide me on how to fix this?



XenForo developer
Staff member
If you can still reproduce this with 2.2.3, that'd be helpful to know. We'd also need you to test with add-ons disabled and also with the default style. I've almost certain that this is a bug that relates to a custom style or an add-on, though debugging is a bit difficult, because the relevant line number is in a dynamically generated file.

The issue here is that this error has been upgrading from a notice to a warning in PHP 8. We suppressed notices in templates (to avoid errors due to variables not being present mostly), so while this same issue would've happened, it simply wouldn't have been logged. This error relates to something that certainly can be a bug so logging it is reasonable. However, for more consistent behavior, we could consider adjusting the code to account for this case.

XF Bug Bot

XenForo bug fixer bot
Staff member
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.4).

Change log:
For consistent behavior across PHP versions, explicitly trigger a notice if an array is passed in to XF::escapeString
There may be a delay before changes are rolled out to the XenForo Community.

Chris D

XenForo developer
Staff member
There are currently no known bugs with PHP 8.0 and the ones we have seen recently haven't been particularly significant and were resolved in the latest release.

So far only 1% of customers are using PHP 8.0.