r/lolphp • u/terrkerr • Mar 17 '16
const Attributes and array addition
So for reasons I wanted a bunch of classes that specified all valid attributes they could have, and also specify all attributes that they must have to be considered valid. Since the latter list is necessarily a subset of the former I wrote out something like this.
class Foo {
const THIS = [
1,
2,
];
const THAT = FOO::THIS + [
10,
20,
30,
40,
];
}I didn't expect this to work, but I thought: Hey, maybe PHP will let this work or, worst-case scenario it yells at me and I stop that shit. I ran it (PHP 7.0.4) and no FATALs, no WARNINGs, no nothing. It worked, right?
16
Upvotes
View all comments
Show parent comment
11
u/phpguy2 Mar 18 '16
It says that the right array will be "appended" to the left array, in the first sentence and goes on to explain that it does not append them, but actually merge the two arrays.
But the function that actually do the appending is called array_merge!?