Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/287.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
常量数组在PHP5.6中工作?_Php_Arrays_Syntax_Constants - Fatal编程技术网

常量数组在PHP5.6中工作?

常量数组在PHP5.6中工作?,php,arrays,syntax,constants,Php,Arrays,Syntax,Constants,在php中,用户提供的注释中指出,现在允许使用const数组。我甚至检查了stackoverflow的其他帖子,他们也这么说。我测试了以下代码: <?php class Constants{ const test = array("a"=>"apple","b"=>"ball","c"=>"car"); } echo Constants::test["b"]; echo Constants::test["c"]; echo Constants::test["

在php中,用户提供的注释中指出,现在允许使用const数组。我甚至检查了stackoverflow的其他帖子,他们也这么说。我测试了以下代码:

<?php

class Constants{
      const test = array("a"=>"apple","b"=>"ball","c"=>"car");
}
echo Constants::test["b"];
echo Constants::test["c"];
echo Constants::test["a"];
?>
上述代码有效。但是,如果我在类外使用
define('test',array(“a”=>“apple”,“b”=>“ball”,“c”=>“car”)
,则这不起作用。这是一个新的未记录的更改,还是仅在我的设置中发生

我的设置是Windows7x64上的PHP5.6.1(32位线程安全)和apache 2.4.10(32位)。我直接从各自的站点下载了它们。我没有使用任何WAMP堆栈

还要注意,我使用netbeans 8.0.1 IDE作为提示,它显示了这个错误。有人知道如何删除它吗

Syntax error
unexpected: [
after:  identifier 'test'
expected:   instanceof, as, =>, }, ',', OR, XOR, &&, ?, ;, ||, &&, |, ^, &, ==, !=, ===, !==, <=,
>=, <, >, <<, >>, +, -, *, /, %, '.', ], (, ), :
----
语法错误
意外:[
之后:标识符“测试”
应为:实例,如,=>,},,',或,XOR,&&&&,?,;,|&&,|,^,&,=,!=,=,!=,!=,!=,,=,,,,,,,,,,,,,,,,,,,,,:
----

显然,如果我在类之外使用const,netbeans IDE中的错误将不会出现

const test = array("a"=>"apple","b"=>"ball","c"=>"car");
echo test["b"];
echo test["c"];
echo test["a"];

这应该行得通!

From:在PHP5.6及更高版本中,常量只能计算为标量值,或标量值或数组值。@RocketHazmat,但他有5个。6@Cheery:我想我看错了问题。@RocketHazmat您正确地阅读了问题。我没有阅读您发布的手册中的页面,该手册指出数组常量确实是在PHP5.6中添加的。无论如何,您知道如何从netbeans中删除错误吗?您可能已经检查过了,但是您的项目属性中的PHP版本设置为5.6了吗?
const test = array("a"=>"apple","b"=>"ball","c"=>"car");
echo test["b"];
echo test["c"];
echo test["a"];