Fixed php 8 compatibility: [E_WARNING] Attempt to read property "prefix_id" on null

Xon

Well-known member
Affected version
2.2.6 patch 2
On updating from php 7.4 to php 8, I immediately started getting these errors;
Code:
ErrorException: Template error: [E_WARNING] Attempt to read property "prefix_id" on null src/XF/Template/Templater.php:3465
Generated by: Unknown account Aug 28, 2021 at 7:22 AM
Stack trace
#0 src/XF/Template/Templater.php(3465): XF\Template\Templater->handleTemplateError(2, '[E_WARNING] Att...', '/var/www/sites/...', 3465)
#1 src/addons/SV/MultiPrefix/XF/Template/Templater.php(178): XF\Template\Templater->fnPrefix(Object(SV\LazyImageLoader\XF\Template\Templater), NULL, 'thread', NULL, 'html', NULL)
#2 src/addons/SV/Threadmarks/XF/Entity/Thread.php(510): SV\MultiPrefix\XF\Template\Templater->fnPrefix(Object(SV\LazyImageLoader\XF\Template\Templater), NULL, 'thread', NULL)
#3 [internal function]: SV\Threadmarks\XF\Entity\Thread->getTitleForThreadmarkList()
#4 src/XF/Template/Templater.php(1184): call_user_func_array(Array, Array)
#5 internal_data/code_cache/templates/l1/s2/public/svThreadmarks_threadmark_list.php(10): XF\Template\Templater->method(Object(SV\CollaborativeThreads\XF\Entity\Thread), 'getTitleForThre...', Array)
#6 src/XF/Template/Templater.php(1644): XF\Template\Templater->{closure}(Object(SV\LazyImageLoader\XF\Template\Templater), Array, NULL)
#7 src/XF/Template/Template.php(24): XF\Template\Templater->renderTemplate('svThreadmarks_t...', Array)
#8 src/XF/Mvc/Renderer/Html.php(48): XF\Template\Template->render()
#9 src/XF/Mvc/Dispatcher.php(458): XF\Mvc\Renderer\Html->renderView('SV\\Threadmarks:...', 'public:svThread...', Array)
#10 src/XF/Mvc/Dispatcher.php(440): XF\Mvc\Dispatcher->renderView(Object(XF\Mvc\Renderer\Html), Object(XF\Mvc\Reply\View))
#11 src/XF/Mvc/Dispatcher.php(400): XF\Mvc\Dispatcher->renderReply(Object(XF\Mvc\Renderer\Html), Object(XF\Mvc\Reply\View))
#12 src/XF/Mvc/Dispatcher.php(58): XF\Mvc\Dispatcher->render(Object(XF\Mvc\Reply\View), 'html')
#13 src/XF/App.php(2344): XF\Mvc\Dispatcher->run()
#14 src/XF.php(512): XF\App->run()
#15 index.php(20): XF::runApp('XF\\Pub\\App')
#16 {main}

Calling the prefix render outside of template rendering used to handle null, but now it errors.

This looks to be because of this code at the start of the fnPrefix function.
PHP:
public function fnPrefix($templater, &$escape, $contentType, $prefixId, $format = 'html', $append = null)
{
   if (!is_int($prefixId))
   {
      $prefixId = $prefixId->prefix_id;
   }

   if (!$prefixId)
   {
      return '';
   }

The test on !is_int($prefixId) should likely be a instanceof test which correctly handles null.
 
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.7).

Change log:
Fix compatibility issue with type checking when rendering prefixes
There may be a delay before changes are rolled out to the XenForo Community.
 
Back
Top Bottom