You created a static array, not a constant array. Static variables are mutable; constants are immutable. Your code is not bad, but it does not do what you intend to do.
In PHP 5.6 you can declare const arrays. See my previous explanations .
Maybe you want something like this:
class MyClass { const MY_ARRAY = array('test1','test2','test3'); public function getMyArray() { return MY_ARRAY; } }
Note that constants do not have the $ prefix, which indicates their immutability. $foo is a variable; FOO no. In addition, persistent names are always capitalized, at least in the programming languages I have been exposed to. This is not performed by the compiler; it's just a (almost?) universal coding style. The visibility keywords public , protected and private do not apply to constants. Finally, static can be applied or can be applied depending on whether you want the function to be static .
jfmercer May 7 '15 at 10:56 p.m. 2015-05-07 22:56
source share