cancel
Showing results for 
Search instead for 
Did you mean: 

Module 'Magento_Theme': ... Namespace error

Module 'Magento_Theme': ... Namespace error

I have been working on magento 2.4.2. While installation I'm facing issues.It gives me error that I have pasted in the subject box. Summary of the error is following.

 

PHP Fatal error: Namespace declaration statement has to be the very first statement or after any declare call in the script in C:\xampp\htdocs\magento\vendor\magento\framework\Image\Adapter\Gd2.php on line 6

 

I have enabled all the extentions required for magento. 

php version = 7.4.26

elasticsearh = 7.0.16

composer = 2.2.2

 

 

3 REPLIES 3

Re: Module 'Magento_Theme': ... Namespace error

In PHP syntax, you should use namespace in the first line.
Can you just open that file and check namespace [PHP_CLASS_PATH];
It should be right after the <?PHP tag starts.
Ensure that your code starts like

<?PHP
namespace Vendor\Module\Folder\Folder;
If issue solved, Click Kudos & Accept as Solution.
LitCommerce - The Most Simple & Affordable Multi-channel Selling Tool

Re: Module 'Magento_Theme': ... Namespace error

@usmansaeedd8c0 

Please follow the below solution:

Open vendor\magento\framework\Image\Adapter\Gd2.php.

At line 96, replace:

private function validateURLScheme(string $filename) : bool
  {
      $allowed_schemes = ['ftp', 'ftps', 'http', 'https'];
      $url = parse_url($filename);
      if ($url && isset($url['scheme']) && !in_array($url['scheme'], $allowed_schemes) {
          return false;
      }

      return true;
  }

With the below code:

private function validateURLScheme(string $filename) : bool
  {
      $allowed_schemes = ['ftp', 'ftps', 'http', 'https'];
      $url = parse_url($filename);
      if ($url && isset($url['scheme']) && !in_array($url['scheme'], $allowed_schemes) && !file_exists($filename)) 
{
          return false;
      }

      return true;
  }

All you have to do is to replace the below string:

 if ($url && isset($url['scheme']) && !in_array($url['scheme'], $allowed_schemes

With:

if ($url && isset($url['scheme']) && !in_array($url['scheme'], $allowed_schemes) && !file_exists($filename))
Problem solved? Click Kudos and "Accept as Solution".
200+ Magento 2 Extensions for Enhanced Shopping Experience.

Re: Module 'Magento_Theme': ... Namespace error

@usmansaeedd8c0 

Please use the below solution:

Open vendor\magento\framework\Image\Adapter\Gd2.php.

At line 96, replace:

private function validateURLScheme(string $filename) : bool
  {
      $allowed_schemes = ['ftp', 'ftps', 'http', 'https'];
      $url = parse_url($filename);
      if ($url && isset($url['scheme']) && !in_array($url['scheme'], $allowed_schemes) {
          return false;
      }
 
      return true;
  }

With the below code:

private function validateURLScheme(string $filename) : bool
  {
      $allowed_schemes = ['ftp', 'ftps', 'http', 'https'];
      $url = parse_url($filename);
      if ($url && isset($url['scheme']) && !in_array($url['scheme'], $allowed_schemes) && !file_exists($filename)) 
{
          return false;
      }

      return true;
  }

All you have to do is to replace the below string:

 if ($url && isset($url['scheme']) && !in_array($url['scheme'], $allowed_schemes

With:

if ($url && isset($url['scheme']) && !in_array($url['scheme'], $allowed_schemes) && !file_exists($filename))
Problem solved? Click Kudos and "Accept as Solution".
200+ Magento 2 Extensions for Enhanced Shopping Experience.