PHP: alternate associative array notation not allowed inside class? -


in php, associative array notation works outside of class:

$array['a'] = array('a', 'b', 'c', 'd'); $array['b'] = array('1', '2', '3', '4'); 

but inside class, similar notation causes 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 works fine:

class foo {     protected $array = array('a'=>array('a', 'b', 'c', 'd'), 'b'=>array('1', '2', '3', '4')); } 

any idea what's going on? allowed notation can cumbersome bigger arrays.

$array['a'] = array('a', 'b', 'c', 'd'); $array['b'] = array('1', '2', '3', '4'); 

this means $array var defined in first line, in second put stuff it. why won't work in class, cannot define same variable twice.

even more, []= modifying operator, can not used in class definition, same reason can not use ++ sign. not deep programming or computer inability that, design decision not logic outside of methods inside class (as opposed js or ruby example).

of course, behaviour can changed "small" c hacking of engine ;-)


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -