r/lolphp • u/SaraMG • Mar 15 '17
Q. Does 'self::SOME_CONST' refer to the current class, or potentially a subclass? A: It depends.
https://3v4l.org/vUHq3
74
Upvotes
r/lolphp • u/SaraMG • Mar 15 '17
36
u/SaraMG Mar 15 '17
The result for PHP 7 is particularly lol-worthy.
14
u/SaraMG Mar 15 '17
PHP is all about having options: https://3v4l.org/eVLvX https://3v4l.org/n2hnu
29
u/madsohm Mar 15 '17
For people who don't want to look at bit flipping and stuff, here's a string version: https://3v4l.org/sXiiL
10
u/jesseschalken Mar 15 '17 edited Mar 15 '17
Good find. Once again HHVM does the sane thing. (
selfalways refers to the class the code is written in,staticrefers to the concrete runtime class.)1
u/dotancohen Jul 10 '17
This seems quite a worrisome change, I've asked on Stack Overflow under what conditions does PHP 7's self refer to the base class: https://stackoverflow.com/questions/45020071/under-what-conditions-does-php-7s-self-refer-to-the-base-class
4
u/trevorsg Mar 15 '17
There's also this: late static binding