Fixed Redundant IO check on loading template

Xon

Well-known member
Affected version
2.2.5
Related to; https://xenforo.com/community/threads/redundant-io-check-on-loading-phrase-group.195751/

In XF\Template\Templater::getTemplateDataFromSource, there is a file_exists check before an include call, which is redundant;

PHP:
protected function getTemplateDataFromSource($type, $name)
{
   $file = $this->getTemplateFilePath($type, $name);
   if (!file_exists($file))
   {
      return false;
   }

   return include($file);
}

include returns false on if the file can't be accessed or readable (the warning is converted into an exception by XF), as such the file_exists check is redundant.

Rough prototyped replacement;
PHP:
protected function getTemplateDataFromSource($type, $name)
{
   $file = $this->getTemplateFilePath($type, $name);
   try
   {
     return include($file);
   }
   catch (\Throwable $e)
   {
     return false;
   }
}
 

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.7).

Change log:
Remove redundant file existence check when loading templates
There may be a delay before changes are rolled out to the XenForo Community.
 
Top