There is a certain conditional function:

function environment() { return 'developer'; } 

And there is a certain conditional class in which the variable is declared:

 сlass SomeClass { private $filename = "/var/www/" . environment() . "/engine/debugger.log"; } 

But for some reason, when executing the code, an error occurs:

Constant expression contains invalid operations

Why can't I call a global function in the class body and how can I achieve the desired result?

    1 answer 1

    Well, it seems that such actions are performed in the class constructor.

     function environment() { return 'developer'; } class SomeClass { private $filename; public function __construct() { $this->filename = "/var/www/" . environment() . "/engine/debugger.log"; } } $obj = new SomeClass; var_dump($obj);