0

I have just installed Magento 2.3, hosting on local server us XAMPP, i get the following message when i try to log on to admin.

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\View\Element\Template\File\Validator.php on line 2

My code in the file reads <?php namespace I have no white space before

  • Which is php version using? – Jimit Bhavsar Jun 24 at 13:34
  • PHP Version 7.2.19 – Mark Jun 24 at 13:47
  • Try with php version 7.1 , i have same issue. working properly with 7.1 instead 7.2 – Jimit Bhavsar Jun 24 at 13:49
  • do i need to reinstall xmapp or can i change the Php version without starting again – Mark Jun 24 at 14:10
0

Sometimes this issue come because of space in PHP start tag of controller facing same issue just removed whitespace in:

<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
namespace Magento\Framework\View\Element\Template\File;

Removing the space resolved my error

0

I cant see any white space in the code

use \Magento\Framework\App\Filesystem\DirectoryList; use Magento\Framework\Component\ComponentRegistrar; use \Magento\Framework\Filesystem\Driver\File as FileDriver;

/** * Class Validator */ class Validator { /** * Config path to 'Allow Symlinks' template settings */ const XML_PATH_TEMPLATE_ALLOW_SYMLINK = 'dev/template/allow_symlink';

/**
 * Template files map
 *
 * @var []
 */
protected $_templatesValidationResults = [];

/**
 * View filesystem
 *
 * @var \Magento\Framework\FileSystem
 */
protected $_filesystem;

/**
 * Allow symlinks flag
 *
 * @var bool
 */
protected $_isAllowSymlinks = false;

/**
 * Root directory
 *
 * @var bool
 */
protected $directory = null;

/**
 * Themes directory
 *
 * @var string
 */
protected $_themesDir;

/**
 * Application directory
 *
 * @var string
 */
protected $_appDir;

/**
 * Compiled templates directory
 *
 * @var string
 */
protected $_compiledDir;

/**
 * @var FileDriver
 */
private $fileDriver;

/**
 * Class constructor
 *
 * @param \Magento\Framework\Filesystem $filesystem
 * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfigInterface
 * @param ComponentRegistrar $componentRegistrar
 * @param string|null $scope
 * @param FileDriver|null $fileDriver
 */
public function __construct(
    \Magento\Framework\Filesystem $filesystem,
    \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfigInterface,
    ComponentRegistrar $componentRegistrar,
    $scope = null,
    ?FileDriver $fileDriver = null
) {
    $this->_filesystem = $filesystem;
    $this->_isAllowSymlinks = $scopeConfigInterface->getValue(self::XML_PATH_TEMPLATE_ALLOW_SYMLINK, $scope);
    $this->_themesDir = $componentRegistrar->getPaths(ComponentRegistrar::THEME);
    $this->moduleDirs = $componentRegistrar->getPaths(ComponentRegistrar::MODULE);
    $this->_compiledDir = $this->_filesystem->getDirectoryRead(DirectoryList::TMP_MATERIALIZATION_DIR)
        ->getAbsolutePath();
    $this->fileDriver = $fileDriver ?: \Magento\Framework\App\ObjectManager::getInstance()->get(FileDriver::class);
}

/**
 * Checks whether the provided file can be rendered.
 *
 * Available directories which are allowed to be rendered
 * (the template file should be located under these directories):
 *  - app
 *  - design
 *
 * @param string $filename
 * @return bool
 */
public function isValid($filename)
{
    $filename = str_replace('\\', '/', $filename);
    if (!isset($this->_templatesValidationResults[$filename])) {
        $this->_templatesValidationResults[$filename] =
            ($this->isPathInDirectories($filename, $this->_compiledDir)
                || $this->isPathInDirectories($filename, $this->moduleDirs)
                || $this->isPathInDirectories($filename, $this->_themesDir)
                || $this->_isAllowSymlinks)
            && $this->getRootDirectory()->isFile($this->getRootDirectory()->getRelativePath($filename));
    }
    return $this->_templatesValidationResults[$filename];
}

/**
 * Checks whether path related to the directory
 *
 * @param string $path
 * @param string|array $directories
 * @return bool
 */
protected function isPathInDirectories($path, $directories)
{
    if (!is_array($directories)) {

s; } $realPath = $this->fileDriver->getRealPath($path); foreach ($directories as $directory) { if (0 === strpos($realPath, $directory)) { return true; } } return false; }

/**
 * Instantiates filesystem directory
 *
 * @return \Magento\Framework\Filesystem\Directory\ReadInterface
 */
protected function getRootDirectory()
{
    if (null === $this->directory) {
        $this->directory = $this->_filesystem->getDirectoryRead(DirectoryList::ROOT);
    }
    return $this->directory;
}

}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.