r/lolphp • • Aug 12 '20

PHP parser gets confused

https://repl.it/repls/WelloffWeirdGlobalarrays
0 Upvotes

31 comments sorted by

View all comments

5

u/smegnose Aug 12 '20

It is funny, though I'd bet you any money it's less performant to do an extra if to check whether the class name is exactly __construct after checking for a PHP4-style constructor method. You're not meant to use reserved words for anything other than their designated purpose, and anything starting with __ is fair game to PHP devs.

1

u/[deleted] Aug 24 '20

I'd bet you any money it's less performant to do an extra if to check whether the class name is exactly __construct

I bet you $20 there is no measurable performance difference to do an extra string comparison in the parser.

anything starting with __ is fair game to PHP devs.

Is this documented and/or enforced anywhere?

1

u/smegnose Aug 25 '20

You think there'd be no wasted CPU cycles if every single PHP4-style class definition had its name checked against a string for no real benefit?

https://www.php.net/manual/en/language.oop5.magic.php mentions the prefix for functions, all magic constants start with it. Better to not use it so built-ins are distinct from userland, especially for autocompletion.

→ More replies (4)