Here is my code:
class Log
{
private $mode = config('my.log.mode');
}
but it throws syntax error ..! Why? what's wrong?
Noted that this works as well:
class Log
{
private $mode;
public function __construct()
{
$this->mode = config('my.log.mode');
}
}
well, what's the point?!
You can initialize properties with constant values only. So, you can't use config() or any other helper here.
Initialization must be a constant value--that is, it must be able to be evaluated at compile time and must not depend on run-time information in order to be evaluated
http://php.net/manual/en/language.oop5.properties.php
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With