Laravel 5.6:无法在构造函数中访问类变量

时间:2018-07-23 14:43:54

标签: php-7 laravel-5.6

我在App \ MyClasses文件夹中有一个自定义类。我想在类内设置一个变量,并且只能从类内的各种方法访问它,因此它可以是私有的。

当我从控制器内部创建类实例时,在构造函数中收到错误“未定义的变量:配置”。你能告诉我我在这里想念什么吗?

我正在使用Laravel 5.6和PHP 7.2。谢谢!

private $configuration;

/**
 * Create a new instance of the connector.
 * @param $userid The logged in user's ID
 * @return void
 */    
public function __construct($userid) {
    //get the configuration object
    $config = User::find($userid)->configuration;
    //dd($config); //OK - has correct data
    $this->$configuration = $config; //'undefined variable: configuration' error here
}

0 个答案:

没有答案
相关问题