Posted on

Deprecated Functionality: explode(): Passing null to parameter #2 ($string) of type string is deprecated in

When running Magento 2.4.4 with PHP 8.1, if I use a block object’s getTemplateFile method AND the block had no template set, I end up with an error that looks like this

1 exception(s):
Exception #0 (Exception): Deprecated Functionality: explode(): Passing null to parameter #2 ($string) of type string is deprecated in /usr/local/var/www/virtual-hosts/agento-2-4-4.localhost/project-community-edition/vendor/magento/framework/View/FileSystem.php on line 174

Exception #0 (Exception): Deprecated Functionality: explode(): Passing null to parameter #2 ($string) of type string is deprecated in /usr/local/var/www/virtual-hosts/magento-2-4-4.localhost/project-community-edition/vendor/magento/framework/View/FileSystem.php on line 174
<pre>#1 explode() called at [vendor/magento/framework/View/FileSystem.php:174]
#2 MagentoFrameworkViewFileSystem::normalizePath() called at [vendor/magento/framework/View/FileSystem.php:119]
#3 MagentoFrameworkViewFileSystem->getTemplateFileName() called at [vendor/magento/framework/View/Element/Template/File/Resolver.php:60]
#4 MagentoFrameworkViewElementTemplateFileResolver->getTemplateFileName() called at [vendor/magento/framework/View/Element/Template.php:214]

If I follow the stack trace to the code in question, I get down to here

#File: vendor/magento/framework/View/FileSystem.php
public static function normalizePath($path)
{
$parts = explode(‘/’, $path);
$result = [];

where is appears Magento is not property guarding/defaulting for the new, more strict, PHP 8.1 expectations around explode.

Is there a safer method to call to get a block’s template? Or is getTemplateFile something we should just expect to throw now and wrap calls in a try/catch.

Leave a Reply

Your email address will not be published.