Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/255.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Codeigniter模型类变量_Php_Class_Codeigniter - Fatal编程技术网

Php Codeigniter模型类变量

Php Codeigniter模型类变量,php,class,codeigniter,Php,Class,Codeigniter,我只是在做这件事时出错了,我不明白为什么 class Budget_model extends CI_Model { // Predefine global class vars private $current_date = date('j'); // Current day date private $current_month = date('n'); // Current month date private $current_year = date(

我只是在做这件事时出错了,我不明白为什么

class Budget_model extends CI_Model
{

    // Predefine global class vars
    private $current_date = date('j');  // Current day date
    private $current_month = date('n'); // Current month date
    private $current_year = date('Y');  // Current year

}
这只会给我这个错误

分析错误:语法错误,中出现意外的“(”,应为“,”或“;” /Applications/MAMP/htdocs/therace/application/models/budget_model.php 在线7


但是为什么?如何解决此问题?

属性不能这样初始化,您需要在构造函数中执行此操作:

private $current_date;

public function __construct()
{
    $this->current_date = date('j');
}

该类是一个蓝图,其属性定义需要独立于任何运行时变量或函数。

属性不能这样初始化,您需要在构造函数中进行初始化:

private $current_date;

public function __construct()
{
    $this->current_date = date('j');
}

类是一个蓝图,其属性定义需要独立于任何运行时变量或函数。

您是否尝试在类构造函数中定义它们?是否尝试在类构造函数中定义它们?