Const Array working in php 5.6? -
in php manual, stated in user contributed notes const array allowed. checked other posts here in stackoverflow , said same. tested next 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 auto apple
the above code works. doesn't work if utilize define('test',array("a"=>"apple","b"=>"ball","c"=>"car")
outside of class. new undocumented alter or happening in setup?
my setup php 5.6.1(32-bit thread safe) , apache 2.4.10 (32-bit) on windows 7 x64. downloaded them respective sites directly. didn't utilize wamp stacks.
also note using netbeans 8.0.1 ide hints , shows error. know how remove it?
syntax error unexpected: [ after: identifier 'test' expected: instanceof, as, =>, }, ',', or, xor, &&, ?, ;, ||, &&, |, ^, &, ==, !=, ===, !==, <=, >=, <, >, <<, >>, +, -, *, /, %, '.', ], (, ), : ----
apparently if utilize const outside of class, error in netbeans ide won't show up.
const test = array("a"=>"apple","b"=>"ball","c"=>"car"); echo test["b"]; echo test["c"]; echo test["a"];
this should work!
php arrays syntax const constants
No comments:
Post a Comment