Click here to Skip to main content
14,880,313 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
This error keeps popping up in one of the classes I use. The error is not tied to any other part of the code it just keeps activating on the first line of code in the Application class.

"
public static string $ROOT_DIR;
" is the problem right now. But if I add a line of code above it the error jumps to that line.

class Application{

    public static string $ROOT_DIR;
    public Router $router;
    public Request $request;
    public Response $response;


    public function __construct($rootPath)
    {
        self::$ROOT_DIR = $rootPath;
        $this->router = new Router();
        $this->request = new Request($this->router);
        $this->response = new Response();
    }

    public function run(){
        echo $this->router->resolve();
    }
}


Also, I think, the error has an effect on this part of my MVC.

class Router{

    public Request $request; (syntax error, unexpected request))
    protected array $routes = [];

    public function __construct(\app\core\Request $request)
    {
        $this->request = $request;
    }


What I have tried:

My guess was it's either a typo or a problem generated because I copied some parts of the code around. But typing the liens of code fresh did nothing.
Posted
Updated 4-Dec-20 2:16am
Comments
Richard MacCutchan 4-Dec-20 7:35am
   
You have unquoted strings in your code. But I am not sure about the first error. What is the full text of the error message?
Demetri K.2 4-Dec-20 15:04pm
   
syntax error, unexpected 'Response'(T_STRING), expecting function (T_FUNCTION) or const (T_CONST)
Richard MacCutchan 5-Dec-20 4:56am
   
That suggests that Response is not defined, although it is different from the original message. Did you write this code, or was it generated from some template?
Demetri K.2 6-Dec-20 4:13am
   
It's from a tutorial. The original was written in php storm.
Richard MacCutchan 6-Dec-20 7:23am
   
Sorry, I only know a bit of plain PHP. You need to talk to the person who wrote the tutorial.

1 solution

My understanding from reading the documentation[^] on this is that static properties don't support the type being explicitly declared. I couldn't find any examples of it, so perhaps just remove the string type declaration?
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900