IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

 PHP Discussion :

Syntax error lors de la mise en ligne du site


Sujet :

PHP

  1. #1
    Candidat au Club
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Avril 2019
    Messages
    4
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Avril 2019
    Messages : 4
    Points : 2
    Points
    2
    Par défaut Syntax error lors de la mise en ligne du site
    Bonjour,

    J'ai un souci lors de la mise en ligne d'un site fait en PHP7.4 et symfony5
    J'ai fais le site en local sans trop de problème, mais lors de la mise en ligne (chez un hébergeur gratuit. Je n'ai pas vraiment le choix) j'avais un problème de version suite au dépendance composeur.
    L'hébergeur mutualisé n'accepte que le PHP7.0, php7.1, 7.2 et 7.3 donc j'ai changer mon WAMP et CLI, fait un "composer config platform-check false" et "composer dumpautoload", suite à ça lors de la migration sur le serveur je n'ai plus eu le message d'erreur sur les version php de mon projet et celui de l'hébergeur.

    Mais maintenant j'ai un autre souci que je n'arrive pas à résoudre.

    J'ai l'erreur suivante :
    syntax error, unexpected 'fn' (T_STRING), expecting :: (T_PAAMAYIM_NEKUDOTAYIM)
    En faisant des tests ça serait mon fichier "index.php" qui pose problème au niveau de $kernel->handle($request); car juste avant cette ligne j'arrive à afficher ma variable request mais le message apparais au moment où je passe dans $response = $kernel->handle($request);

    fichier dans : monProjet/public/index.php
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
     
    <?php
     
    use App\Kernel;
    use Symfony\Component\Dotenv\Dotenv;
    use Symfony\Component\ErrorHandler\Debug;
    use Symfony\Component\HttpFoundation\Request;
     
    require dirname(__DIR__).'/vendor/autoload.php';
    (new Dotenv())->bootEnv(dirname(__DIR__).'/.env');
     
    if ($_SERVER['APP_DEBUG']) {
        umask(0000);
     
        Debug::enable();
    }
     
    if ($trustedProxies = $_SERVER['TRUSTED_PROXIES'] ?? $_ENV['TRUSTED_PROXIES'] ?? false) {
        Request::setTrustedProxies(explode(',', $trustedProxies), Request::HEADER_X_FORWARDED_ALL ^ Request::HEADER_X_FORWARDED_HOST);
    }
     
    if ($trustedHosts = $_SERVER['TRUSTED_HOSTS'] ?? $_ENV['TRUSTED_HOSTS'] ?? false) {
        Request::setTrustedHosts([$trustedHosts]);
    }
     
    $kernel = new Kernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']);
    $request = Request::createFromGlobals();
    $response = $kernel->handle($request);
    $response->send();
    $kernel->terminate($request, $response);

    Mon fichier .htaccess
    Code apache : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
     
    DirectoryIndex index.php
     
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>
     
    <IfModule mod_rewrite.c>
        RewriteEngine On
        RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
        RewriteRule ^(.*) - [E=BASE:%1]
        RewriteCond %{HTTP:Authorization} .
        RewriteRule ^ - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
        RewriteCond %{ENV:REDIRECT_STATUS} ^$
        RewriteRule ^index\.php(?:/(.*)|$) %{ENV:BASE}/$1 [R=301,L]
        RewriteCond %{REQUEST_FILENAME} -f
        RewriteRule ^ - [L]
        RewriteRule ^ %{ENV:BASE}/index.php [L]
    </IfModule>

    Voici mon fichier log
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
     
    [2021-04-22T23:40:07.494061+03:00] request.INFO: Matched route "show_all_article". {"route":"show_all_article","route_parameters":{"_route":"show_all_article","_controller":"App\\Controller\\ArticleController::ShowAllArticle"},"request_uri":"http://flevallis.orgfree.com/public/","method":"GET"} []
    [2021-04-22T23:40:07.507601+03:00] security.DEBUG: Checking for guard authentication credentials. {"firewall_key":"main","authenticators":1} []
    [2021-04-22T23:40:07.508019+03:00] php.WARNING: Warning: include(/home/vhosts/flevallis.orgfree.com/vendor/composer/../../src/Security/LoginFormAuthenticator.php): failed to open stream: No such file or directory {"exception":"[object] (ErrorException(code: 0): Warning: include(/home/vhosts/flevallis.orgfree.com/vendor/composer/../../src/Security/LoginFormAuthenticator.php): failed to open stream: No such file or directory at /home/vhosts/flevallis.orgfree.com/vendor/composer/ClassLoader.php:476)"} []
    [2021-04-22T23:40:07.508173+03:00] php.WARNING: Warning: include(/home/vhosts/flevallis.orgfree.com/vendor/composer/../../src/Security/LoginFormAuthenticator.php): failed to open stream: No such file or directory {"exception":"[object] (ErrorException(code: 0): Warning: include(/home/vhosts/flevallis.orgfree.com/vendor/composer/../../src/Security/LoginFormAuthenticator.php): failed to open stream: No such file or directory at /home/vhosts/flevallis.orgfree.com/vendor/composer/ClassLoader.php:476)"} []
    [2021-04-22T23:40:07.508241+03:00] php.WARNING: Warning: include(): Failed opening '/home/vhosts/flevallis.orgfree.com/vendor/composer/../../src/Security/LoginFormAuthenticator.php' for inclusion (include_path='.:/opt/remi/php73/root/usr/share/pear:/opt/remi/php73/root/usr/share/php:/usr/share/pear:/usr/share/php') {"exception":"[object] (ErrorException(code: 0): Warning: include(): Failed opening '/home/vhosts/flevallis.orgfree.com/vendor/composer/../../src/Security/LoginFormAuthenticator.php' for inclusion (include_path='.:/opt/remi/php73/root/usr/share/pear:/opt/remi/php73/root/usr/share/php:/usr/share/pear:/usr/share/php') at /home/vhosts/flevallis.orgfree.com/vendor/composer/ClassLoader.php:476)"} []
    [2021-04-22T23:40:07.508483+03:00] php.CRITICAL: Uncaught Error: Class 'App\Security\LoginFormAuthenticator' not found {"exception":"[object] (Error(code: 0): Class 'App\\Security\\LoginFormAuthenticator' not found at /home/vhosts/flevallis.orgfree.com/var/cache/prod/ContainerQMNezLt/getLoginFormAuthenticatorService.php:20)"} []
    [2021-04-22T23:40:08.667227+03:00] request.CRITICAL: Uncaught PHP Exception Symfony\Component\ErrorHandler\Error\ClassNotFoundError: "Attempted to load class "LoginFormAuthenticator" from namespace "App\Security". Did you forget a "use" statement for another namespace?" at /home/vhosts/flevallis.orgfree.com/var/cache/prod/ContainerQMNezLt/getLoginFormAuthenticatorService.php line 20 {"exception":"[object] (Symfony\\Component\\ErrorHandler\\Error\\ClassNotFoundError(code: 0): Attempted to load class \"LoginFormAuthenticator\" from namespace \"App\\Security\".\nDid you forget a \"use\" statement for another namespace? at /home/vhosts/flevallis.orgfree.com/var/cache/prod/ContainerQMNezLt/getLoginFormAuthenticatorService.php:20)"} []
    [2021-04-22T23:40:08.669373+03:00] php.WARNING: Warning: include(/home/vhosts/flevallis.orgfree.com/vendor/composer/../twig/twig/src/Loader/FilesystemLoader.php): failed to open stream: No such file or directory {"exception":"[object] (ErrorException(code: 0): Warning: include(/home/vhosts/flevallis.orgfree.com/vendor/composer/../twig/twig/src/Loader/FilesystemLoader.php): failed to open stream: No such file or directory at /home/vhosts/flevallis.orgfree.com/vendor/composer/ClassLoader.php:476)"} []
    [2021-04-22T23:40:08.669609+03:00] php.WARNING: Warning: include(/home/vhosts/flevallis.orgfree.com/vendor/composer/../twig/twig/src/Loader/FilesystemLoader.php): failed to open stream: No such file or directory {"exception":"[object] (ErrorException(code: 0): Warning: include(/home/vhosts/flevallis.orgfree.com/vendor/composer/../twig/twig/src/Loader/FilesystemLoader.php): failed to open stream: No such file or directory at /home/vhosts/flevallis.orgfree.com/vendor/composer/ClassLoader.php:476)"} []
    [2021-04-22T23:40:08.669737+03:00] php.WARNING: Warning: include(): Failed opening '/home/vhosts/flevallis.orgfree.com/vendor/composer/../twig/twig/src/Loader/FilesystemLoader.php' for inclusion (include_path='.:/opt/remi/php73/root/usr/share/pear:/opt/remi/php73/root/usr/share/php:/usr/share/pear:/usr/share/php') {"exception":"[object] (ErrorException(code: 0): Warning: include(): Failed opening '/home/vhosts/flevallis.orgfree.com/vendor/composer/../twig/twig/src/Loader/FilesystemLoader.php' for inclusion (include_path='.:/opt/remi/php73/root/usr/share/pear:/opt/remi/php73/root/usr/share/php:/usr/share/pear:/usr/share/php') at /home/vhosts/flevallis.orgfree.com/vendor/composer/ClassLoader.php:476)"} []
    [2021-04-22T23:40:08.669866+03:00] php.CRITICAL: Uncaught Error: Class 'Twig\Loader\FilesystemLoader' not found {"exception":"[object] (Error(code: 0): Class 'Twig\\Loader\\FilesystemLoader' not found at /home/vhosts/flevallis.orgfree.com/var/cache/prod/ContainerQMNezLt/get_Container_Private_TwigService.php:20)"} []
    et mon fichier dans src/security/LoginFormAuthenticator.php
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
     
    <?php
     
    namespace App\Security;
     
    use App\Entity\Users;
    use Doctrine\ORM\EntityManagerInterface;
    use Symfony\Component\HttpFoundation\RedirectResponse;
    use Symfony\Component\HttpFoundation\Request;
    use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
    use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
    use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
    use Symfony\Component\Security\Core\Exception\CustomUserMessageAuthenticationException;
    use Symfony\Component\Security\Core\Exception\InvalidCsrfTokenException;
    use Symfony\Component\Security\Core\Security;
    use Symfony\Component\Security\Core\User\UserInterface;
    use Symfony\Component\Security\Core\User\UserProviderInterface;
    use Symfony\Component\Security\Csrf\CsrfToken;
    use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
    use Symfony\Component\Security\Guard\Authenticator\AbstractFormLoginAuthenticator;
    use Symfony\Component\Security\Guard\PasswordAuthenticatedInterface;
    use Symfony\Component\Security\Http\Util\TargetPathTrait;
     
    class LoginFormAuthenticator extends AbstractFormLoginAuthenticator implements PasswordAuthenticatedInterface
    {
        use TargetPathTrait;
     
        public const LOGIN_ROUTE = 'app_login';
     
        private $entityManager;
        private $urlGenerator;
        private $csrfTokenManager;
        private $passwordEncoder;
     
        public function __construct(EntityManagerInterface $entityManager, UrlGeneratorInterface $urlGenerator, CsrfTokenManagerInterface $csrfTokenManager, UserPasswordEncoderInterface $passwordEncoder)
        {
            $this->entityManager = $entityManager;
            $this->urlGenerator = $urlGenerator;
            $this->csrfTokenManager = $csrfTokenManager;
            $this->passwordEncoder = $passwordEncoder;
        }
     
        public function supports(Request $request)
        {
            return self::LOGIN_ROUTE === $request->attributes->get('_route')
                && $request->isMethod('POST');
        }
     
        public function getCredentials(Request $request)
        {
            $credentials = [
                'email' => $request->request->get('email'),
                'password' => $request->request->get('password'),
                'csrf_token' => $request->request->get('_csrf_token'),
            ];
            $request->getSession()->set(
                Security::LAST_USERNAME,
                $credentials['email']
            );
     
            return $credentials;
        }
     
        public function getUser($credentials, UserProviderInterface $userProvider)
        {
            $token = new CsrfToken('authenticate', $credentials['csrf_token']);
            if (!$this->csrfTokenManager->isTokenValid($token)) {
                throw new InvalidCsrfTokenException();
            }
     
            $user = $this->entityManager->getRepository(Users::class)->findOneBy(['email' => $credentials['email']]);
     
            if (!$user) {
                // fail authentication with a custom error
                throw new CustomUserMessageAuthenticationException('Adresse mail ou mot de passe incorrect');
            }
            return $user;
        }
     
        public function checkCredentials($credentials, UserInterface $user)
        {
            return $this->passwordEncoder->isPasswordValid($user, $credentials['password']);
        }
     
        /**
         * Used to upgrade (rehash) the user's password automatically over time.
         */
        public function getPassword($credentials): ?string
        {
            return $credentials['password'];
        }
     
        public function onAuthenticationSuccess(Request $request, TokenInterface $token, $providerKey)
        {
            if ($targetPath = $this->getTargetPath($request->getSession(), $providerKey)) {
                return new RedirectResponse($targetPath);
            }
     
            // For example : 
            return new RedirectResponse($this->urlGenerator->generate('show_all_article'));
            // throw new \Exception('TODO: provide a valid redirect inside '.__FILE__);
        }
     
        protected function getLoginUrl()
        {
            return $this->urlGenerator->generate(self::LOGIN_ROUTE);
        }
    }

    Le site marche sans problème en local mais pas quand il est mis en ligne. J'ai ce fameux errorx syntax
    Est-ce que quelqu'un aurait des pistes où je pourrais regarder ?
    Merci d'avoir lu mon message.
    Images attachées Images attachées  

  2. #2
    Expert éminent sénior
    Avatar de mathieu
    Profil pro
    Inscrit en
    Juin 2003
    Messages
    10 235
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2003
    Messages : 10 235
    Points : 15 532
    Points
    15 532
    Par défaut
    faites un fichier php tout simple avec le code phpinfo(); pour voir la version qui est en place actuellement.

  3. #3
    Expert éminent
    Avatar de Séb.
    Profil pro
    Inscrit en
    Mars 2005
    Messages
    5 101
    Détails du profil
    Informations personnelles :
    Âge : 46
    Localisation : France

    Informations professionnelles :
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Mars 2005
    Messages : 5 101
    Points : 8 211
    Points
    8 211
    Billets dans le blog
    17
    Par défaut
    Vu le message d'erreur tu dois avoir un appel à une fonction anonyme de forme raccourcie $result = fn($param) => ...

    Ces fonctions sont apparues avec PHP 7.4
    Un problème exposé clairement est déjà à moitié résolu
    Keep It Smart and Simple

  4. #4
    Candidat au Club
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Avril 2019
    Messages
    4
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Avril 2019
    Messages : 4
    Points : 2
    Points
    2
    Par défaut
    Citation Envoyé par mathieu Voir le message
    faites un fichier php tout simple avec le code phpinfo(); pour voir la version qui est en place actuellement.
    Merci pour votre aide.
    N'arrivant pas à mettre le phpinfo() dans le corp du texte sur développez.com, je l'insère en t'en que lien ci-dessous.
    Voici le lien du phpinfo()

    http://flevallis.orgfree.com/public/phpinfo.php

  5. #5
    Candidat au Club
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Avril 2019
    Messages
    4
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Avril 2019
    Messages : 4
    Points : 2
    Points
    2
    Par défaut
    Citation Envoyé par Séb. Voir le message
    Vu le message d'erreur tu dois avoir un appel à une fonction anonyme de forme raccourcie $result = fn($param) => ...

    Ces fonctions sont apparues avec PHP 7.4
    Merci pour ton aide.

    Je recherche mais ne vois pas si j'ai fais une fonction de ce genre.
    Comment faire pour retrouver cette fonction anonyme ?
    J'ai fais une recherche sur mon IDE (visual studio code) en y indiquant fn mais il ne trouve rien.
    Comment puis-je retrouver cette fonction anonyme et réparer l'erreur ?

  6. #6
    Expert éminent sénior
    Avatar de mathieu
    Profil pro
    Inscrit en
    Juin 2003
    Messages
    10 235
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2003
    Messages : 10 235
    Points : 15 532
    Points
    15 532
    Par défaut
    Citation Envoyé par aurigoth Voir le message
    N'arrivant pas à mettre le phpinfo() dans le corp du texte sur développez.com, je l'insère en t'en que lien ci-dessous.
    je demandais ça juste pour voir la version de php qui est 7.3.21.
    mais au final l'url m'a permis de voir le message d'erreur complet :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    ParseError:
    syntax error, unexpected 'fn' (T_STRING), expecting :: (T_PAAMAYIM_NEKUDOTAYIM)
     
      at /home/vhosts/flevallis.orgfree.com/vendor/laminas/laminas-code/src/Generator/ClassGenerator.php:480
      at Symfony\Component\ErrorHandler\DebugClassLoader->loadClass('Laminas\\Code\\Generator\\ClassGenerator')
      at spl_autoload_call('Laminas\\Code\\Generator\\ClassGenerator')
      at class_exists('Laminas\\Code\\Generator\\ClassGenerator')
         (/home/vhosts/flevallis.orgfree.com/vendor/laminas/laminas-zendframework-bridge/src/Autoloader.php:167)
      at Laminas\ZendFrameworkBridge\Autoloader::Laminas\ZendFrameworkBridge\{closure}('Zend\\Code\\Generator\\ClassGenerator')
         (/home/vhosts/flevallis.orgfree.com/vendor/symfony/error-handler/DebugClassLoader.php:350)
      at Symfony\Component\ErrorHandler\DebugClassLoader->loadClass('Zend\\Code\\Generator\\ClassGenerator')
      at spl_autoload_call('Zend\\Code\\Generator\\ClassGenerator')
    et en regardant dans le fichier "laminas-code/src/Generator/ClassGenerator.php" je suis tombé sur ça :
    https://github.com/laminas/laminas-c...rator.php#L478
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
        public function hasImplementedInterface($implementedInterface)
        {
            $interfaceType = TypeGenerator::fromTypeString($implementedInterface);
     
            return (bool) array_filter(
                array_map([TypeGenerator::class, 'fromTypeString'], $this->implementedInterfaces),
                static fn (TypeGenerator $interface): bool => $interfaceType->equals($interface)
            );
        }
    donc comme le disait Séb., il faut PHP 7.4 pour utiliser cela.

  7. #7
    Candidat au Club
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Avril 2019
    Messages
    4
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Avril 2019
    Messages : 4
    Points : 2
    Points
    2
    Par défaut
    Ok je comprend mieux. Merci à vous 2.
    Donc pas le choix soit avoir un hébergeur en PHP7.4 soit refaire le site en PHP7.3.

    Merci beaucoup pour vos message.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. WCF et WMI : problème lors de la mise en ligne
    Par tom741 dans le forum Windows Communication Foundation
    Réponses: 3
    Dernier message: 13/09/2010, 12h28
  2. Message d'erreur DB ERROR lors d'une mise à jour
    Par Rony Rauzduel dans le forum Administration
    Réponses: 4
    Dernier message: 03/03/2010, 22h09
  3. [MySQL] Erreur lors de la mise en ligne d'un site
    Par audreysensei dans le forum PHP & Base de données
    Réponses: 2
    Dernier message: 03/09/2009, 11h59
  4. Réponses: 1
    Dernier message: 04/11/2008, 14h17
  5. Problème lors de la mise en ligne
    Par Flashball dans le forum Langage
    Réponses: 5
    Dernier message: 27/12/2006, 19h03

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo