PHP5.6 are arrays allowed in CLASS constants
10,056
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);
Author by
Hao Chang
Updated on July 19, 2022Comments
-
Hao Chang almost 2 years
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?