While working with an OOP script in PHP upon parsing I get a syntax error I know shouldn’t be there. The syntax is perfect.
class Organism
{
private $ex = array(0=>"Hello",1=>"world!");
public $ex2 = array_rand($ex,1);
}
Gives me the error of
Parse error: syntax error, unexpected ‘(‘, expecting ‘,’ or ‘;’
In PHP you must implement constructor and assign default values for your variables there.
Solution: