简体   繁体   English

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

[英]PHP5.6 are arrays allowed in CLASS constants

So we can define array constants in PHP5.6. 所以我们可以在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? 那么数组常量是允许的,但不是在类内部吗?

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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM