gpt4 book ai didi

PHP5.6 CLASS常量中允许数组

转载 作者:可可西里 更新时间:2023-11-01 13:17:20 26 4
gpt4 key购买 nike

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

Arrays are not allowed in class constants

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

最佳答案

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

参见 link一个有效的 php 代码。

<?php

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

print_r(Foo::BAR);

关于PHP5.6 CLASS常量中允许数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38900385/

26 4 0
文章推荐: html - 使用 标签相对于
文章推荐: php调用嵌套函数
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com