So we can define array constants in PHP5.6. However, I got the following error when defining an array constant inside a class
所以我们可以在PHP5.6中定义数组常量。但是,在类中定义数组常量时出现以下错误
Arrays are not allowed in class constants
So is it true that array constants are allowed but not inside classes?
那么数组常量是允许的,但不允许在类内部吗?
1 个解决方案
#1
7
As of PHP 5.6 arrays are allowed in class constants.
从PHP 5.6开始,类常量中允许使用数组。
See the link for a working php code.
请参阅有关正常运行的php代码的链接。
<?php
class Foo
{
const BAR = [1,2,3];
}
print_r(Foo::BAR);
#1
7
As of PHP 5.6 arrays are allowed in class constants.
从PHP 5.6开始,类常量中允许使用数组。
See the link for a working php code.
请参阅有关正常运行的php代码的链接。
<?php
class Foo
{
const BAR = [1,2,3];
}
print_r(Foo::BAR);