Gearing Man Gearing Man - 5 months ago 52
PHP Question

FATAL ERROR Arrays are not allowed in class constants

Following code works in my pc but not in server throws FATAL ERROR Arrays are not allowed in class constants on line number 3

class myClass{
const CITY = ['Kolkata', 'Chennai', 'Delhi'];
}

foreach(myClass::CITY as $city ){
echo '<br />'.$city;
}

Answer

Possible duplicate of PHP Constants Containing Arrays?.

Anyway, PHP constant array supports from PHP version >=5.6. Here is the reference http://php.net/manual/en/migration56.new-features.php. Please check your PHP version.