Const Array works in php 5.6?

In the php manual , user contributed notes that const array is now allowed. I even checked other posts here on stackoverflow and they said the same thing. I checked the following code:

<?php

class Constants{
      const test = array("a"=>"apple","b"=>"ball","c"=>"car");
}
echo Constants::test["b"];
echo Constants::test["c"];
echo Constants::test["a"];
?>

      

Output:

ball
car
apple

      

The above code works. However, this doesn't work if I use it define('test',array("a"=>"apple","b"=>"ball","c"=>"car")

outside of the class. Is this a new undocumented change or is it only happening in my setup?

My setup is php 5.6.1 (32-bit thread security) and apache 2.4.10 (32-bit) for Windows 7 x64. I downloaded them from their respective sites directly. I have not used any WAMP stacks.

Also note that I am using NetBeans 8.0.1 IDE for tooltips and is showing this error. Does anyone know how to remove it?

Syntax error
unexpected: [
after:  identifier 'test'
expected:   instanceof, as, =>, }, ',', OR, XOR, &&, ?, ;, ||, &&, |, ^, &, ==, !=, ===, !==, <=,
>=, <, >, <<, >>, +, -, *, /, %, '.', ], (, ), :
----

      

+3


source to share


1 answer


Apparently if I use const outside the class the error in the netbeans IDE will not show.

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

      



It should work!

0


source







All Articles