In PHP, this associative array notation works outside of a class:
$array['a'] = array('a', 'b', 'c', 'd');
$array['b'] = array('1', '2', '3', '4');
But inside a class, similar notation causes an error:
class Foo {
protected $array['a'] = array('a', 'b', 'c', 'd');
protected $array['b'] = array('1', '2', '3', '4');
}
//Parse error: syntax error, unexpected '[', expecting ',' or ';'
And yet this works just fine:
class Foo {
protected $array = array('a'=>array('a', 'b', 'c', 'd'), 'b'=>array('1', '2', '3', '4'));
}
Any idea what's going on? The allowed notation can get really cumbersome with bigger arrays.