PHP5.6是CLASS常量中允许的数组

Hao*_*ang 7 php arrays class constants php-5.6

所以我们可以在PHP5.6中定义数组常量.但是,在类中定义数组常量时出现以下错误

Arrays are not allowed in class constants
Run Code Online (Sandbox Code Playgroud)

那么数组常量是允许的,但不是在类内部吗?

小智 8

从PHP 5.6开始,类常量中允许使用数组.

查看有用的PHP代码的链接.

<?php

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

print_r(Foo::BAR);
Run Code Online (Sandbox Code Playgroud)