11
I found way too this new Feature of PHP 5.6.
It is now possible to define a array
for the value of a constant.
Look how cool:
const BR_DATES = [
1 => 'Janeiro',
2 => 'Fevereiro',
3 => 'Março',
4 => 'Abril'
];
print_r(BR_DATES); // Array ( [1] => Janeiro [2] => Fevereiro [3] => Março [4] => Abril )
echo BR_DATES[date('n')]; // Março
I see that this implementation reduces pollution in the global scope compared to the definition of numerous constants. In addition, it becomes very useful in reusing values that could be used in a fixed way, as in the above case.
In addition to the highlighted advantages, what are other advantages that this new implementation will bring?
This implementation of the constant accepting an array would be the same thing as the Tuple do Python?
This implementation brings some harm compared to previous versions?
@gmsantos, thank you so much for the correction. I just didn’t agree much with the
5.6.6
turn5.6
. 'Cause I had php5.6.0
, and this resource was NOT implemented. I just don’t know if this is due to the ALPHA phase and not the stable one– Wallace Maxters
I’m going based on changelog. Changes like this do not appear between patch versions, they are only for bugfixes.
– gmsantos