michaela
michaela

Reputation: 171

Unexpected error in date?

I am getting an error as read below:

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

when I try and save the date to a variable. Here is my code... (PHP)

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

Upvotes: 0

Views: 736

Answers (1)

MrCode
MrCode

Reputation: 64536

You should set your property defaults in the constructor:

class Something
{
    protected $title;

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

}

Upvotes: 2

Related Questions