html - Fatal error: Constant expression contains invalid operations in /PATH/initClass.php on line 5
Get the solution ↓↓↓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.
Answer
Solution:
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;
}
}
?>
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: using $this when not in object context laravel
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.