I need to define a constant array within the scope of an class, which is to be used statically (i.e. I am not creating an instance of the class). Here is the sample code which works in PHP5, but not in PHP4:
class MyTest {
static $arr = array(100, 200);
function test() {
print_r(MyTest::$arr);
}
}
MyTest::test();
How can I change this code so it works in PHP4 (4.4.9-pl0-gentoo)?
Remarks:
GLOBALS
as the code has to work within phpunit
unit-testing. When doing so, an array defined as GLOBAL
in the header of the file is not seen within the unittest. class MyTest {
public function getArray() {
return array(100, 200);
}
}
Not pretty, but you can simply call MyTest::getArray()
without creating an instance (or $this->getArray()
from inside the class) to retrieve the data.