Dj aman motihari
Dj aman motihari

Reputation: 103

Fatal error: Constant expression contains invalid operations in /PATH/initClass.php on line 5

I am getting the following error!

Fatal error: Constant expression contains invalid operations in >/PATH/initClass.php on line 5

For the code:

<?php
Class init
{
    public const THEME = "aman/dev/frontend/";
    private $root = dirname(__dir__)."/aman/dev/fontend/";
    public function getFile($name,$value)
    {
        list(
            $title
            ) = $value;


    }
}
?>

I can't seem to figure out what's is happening.

Help would be appreciated.

Upvotes: 0

Views: 367

Answers (1)

Hassan Al-Jeshi
Hassan Al-Jeshi

Reputation: 1498

Your problem is that you are using a function operation to set a value to a class variable. To fix your problem, use the following code (i.e. move initialization to the constructor)

<?php
Class init
{
    public const THEME = "aman/dev/frontend/";
    private $root;

    public function __construct() {
        $this->root =  dirname(__dir__)."/aman/dev/fontend/";
    }

    public function getFile($name,$value)
    {
        list(
            $title
            ) = $value;


    }
}
?>

Upvotes: 2

Related Questions