Adding a class const in php version 7.4 causes a required file to not be found

I'm getting the following exception error when I try to create a class level constant in my controller:

Expected to find class "App\common_code\site_constants" in file 
"/var/www/vhosts/symfony5/proj/src/common_code/site_constants.php"
while importing services from resource "../src/", but it was not
found! Check the namespace prefix used with the resource in
/var/www/vhosts/symfony5/proj/src/../config/services.yaml (which
is being imported from
"/var/www/vhosts/symfony5/proj/src/Kernel.php").

Here is my code:

<?php

// src/Controller/myController.php

namespace App\Controller;

use Symfony\Component\Routing\Annotation\Route;

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;

class myController {

    // Class-Level local private constants.

    //
    // Adding this one constant causes an error about the
    // site_constants.php require file not being found.
    // Commenting this out and this error and no others happen.
    //

    private const PASSWORD_PROMPT = 'Enter a password.';

    /**
     * @Route("/BreakinOut/home")
     */
    public function home() : Response {

        //
        // Include the site_contants.php file that is
        // outside of the Controller directory, so the
        // file can contain just a
        // bunch of code.
        //

        require ( '../common_code/site_constants.php' );

        return new Response( 'Hi' );

    }
    // public home() : Response  function.

}

?>

The site_constants.php file only contains a few define statements, and none are for PASSWORD_PROMPT.

Why does adding the one constant cause this error?

Thanks.



from Recent Questions - Stack Overflow https://ift.tt/3t67NxG
https://ift.tt/eA8V8J

Comments

Popular posts from this blog

Today Walkin 14th-Sept

Spring Elasticsearch Operations

Hibernate Search - Elasticsearch with JSON manipulation