tags:

views:

89

answers:

1

Why is this giving error?

class content {
    protected $id,$title,$content,$image,$imagedirectory,$page;
    protected $sid = md5(time()); //In this line : parse error, expecting `','' or `';''
}
+7  A: 

md5(time()) is an expression.

Field initializations are not allowed to use expressions, only literals.

Instead, you could do:

class content {
    protected $id, $title, $content, $image, $imagedirectory, $page, $sid;

    public function __construct()
    {
        $this->sid = md5(time());
    }
}
Coronatus
+5 votes, but no one noticed the error in his answer. 2 ` = = ` in your function. Anyways I will fix it.
Starx
@Starx - oops and thanks!
Coronatus