日期出现意外错误?

时间:2012-04-20 15:09:37

标签: php date

我收到如下错误:

Parse error: syntax error, unexpected '(', expecting ',' or ';' in X:\xampp\htdocs\lib.php on line 15

当我尝试将日期保存到变量时。这是我的代码......(PHP)

protected $title = date('D, d M Y');

1 个答案:

答案 0 :(得分:2)

您应该在构造函数中设置属性默认值:

class Something
{
    protected $title;

    public function __construct()
    {
        $this->title = date('D, d M Y');
    }

}