TeamSpeak Fixed ErrorException: [E_WARNING] Only the first byte will be assigned to the string offset in src\addons\NF\TeamSpeak\Viewer.php at line 503

Affected add-on version
2.2.0
After upgrading from PHP 7.4 to PHP 8.1, the following error is displayed when visiting /account/teamspeak:

Code:
ErrorException: [E_WARNING] Only the first byte will be assigned to the string offset in src\addons\NF\TeamSpeak\Viewer.php at line 503
XF::handlePhpError() in src\addons\NF\TeamSpeak\Viewer.php at line 503
NF\TeamSpeak\Viewer->getServerTree() in src\addons\NF\TeamSpeak\XF\Pub\Controller\Account.php at line 61
NF\TeamSpeak\XF\Pub\Controller\Account->actionTeamSpeak() in src\XF\Mvc\Dispatcher.php at line 352
XF\Mvc\Dispatcher->dispatchClass() in src\XF\Mvc\Dispatcher.php at line 259
XF\Mvc\Dispatcher->dispatchFromMatch() in src\XF\Mvc\Dispatcher.php at line 115
XF\Mvc\Dispatcher->dispatchLoop() in src\XF\Mvc\Dispatcher.php at line 57
XF\Mvc\Dispatcher->run() in src\XF\App.php at line 2353
XF\App->run() in src\XF.php at line 524
XF::runApp() in index.php at line 20

As of PHP 8 trying to replace a string offset with more than one byte using square array brackets style will emit a warning (so it's PHP 8.0 as well - the recommended version for XenForo).
 
I am getting same error, I upgraded to new server and PHP 8.1
Quickfix:
  • Comment line 503 in /src/addons/NF/TeamSpeak/Viewer.php
  • Change line 505 from if (!$g_temp) to if (!$g_temp && is_array($g_temp))

This will, of course, result in file health checker warnings unless you remove the Viewer.php from hashes.json.
 
Back
Top