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