PHP5.6 are arrays allowed in CLASS constants

Hao Chang picture Hao Chang · Aug 11, 2016 · Viewed 9.2k times · Source

So we can define array constants in PHP5.6. However, I got the following error when defining an array constant inside a class

Arrays are not allowed in class constants

So is it true that array constants are allowed but not inside classes?

Answer

Whiteulver picture Whiteulver · Aug 11, 2016

As of PHP 5.6 arrays are allowed in class constants.

See the link for a working php code.

<?php

class Foo 
{
    const BAR = [1,2,3];
}

print_r(Foo::BAR);