Fixed PHP 8.1 [E_DEPRECATED] json_decode(): Passing null to parameter (in XF/Entity/Thread::rebuildFirstPostInfo)

Painbaker

Well-known member
Affected version
2.2.11
Code:
ErrorException: [E_DEPRECATED] json_decode(): Passing null to parameter #1 ($json) of type string is deprecated in src/XF/Entity/Thread.php at line 987
XF::handlePhpError()
json_decode() in src/XF/Entity/Thread.php at line 987

XF\Entity\Thread->rebuildFirstPostInfo() in src/XF/Entity/Thread.php at line 959
XF\Entity\Thread->rebuildCounters() in src/XF/Job/Thread.php at line 34
XF\Job\Thread->rebuildById() in src/XF/Job/AbstractRebuildJob.php at line 47
XF\Job\AbstractRebuildJob->run() in src/XF/Job/Atomic.php at line 40
XF\Job\Atomic->run() in src/XF/Job/Manager.php at line 260
XF\Job\Manager->runJobInternal() in src/XF/Job/Manager.php at line 202
XF\Job\Manager->runJobEntry() in src/XF/Job/Manager.php at line 118
XF\Job\Manager->runByIds() in src/XF/Admin/Controller/Tools.php at line 122
XF\Admin\Controller\Tools->actionRunJob() 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 admin.php at line 13

There should be a NULL check here for PHP 8.1+ compatibility:

XF/Entity/Thread::rebuildFirstPostInfo
PHP:
    public function rebuildFirstPostInfo()
    {
       ...
        $this->first_post_reactions = json_decode($firstPost['reactions'], true) ?: [];

        return true;
    }
 
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.12).

Change log:
Fix PHP 8.1 compatibility issue when rebuilding a thread's first post information
There may be a delay before changes are rolled out to the XenForo Community.
 
Back
Top Bottom