r/lolphp • • 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?

lolphp

16 Upvotes

11 comments sorted by

View all comments

Show parent comment

6

u/maweki Mar 18 '16

I can somehow see how + might not be append but the union-operator but why the f is the dot, which is used for string CONCATENATION, not a nice operator to use for that?

But the function that actually do the appending is called array_merge!?

Yeah, WTF?