Re:PHP: why GOTO instead of recursion?
by masklinn on Tuesday September 23, 2014 @12:41PM
(#8356262)
> That would (partially) explain why you can't statically evaluate it to `\true`.
Yes, but that only requires a guard clause. That's what CPython 2 does in the same situation:
>>> import dis
>>> def foo():
... while True:
... print "ok"
...
>>> dis.dis(foo)
2 0 SETUP_LOOP 15 (to 18)
>> 3 LOAD_GLOBAL 0 (True)
6 POP_JUMP_IF_FALSE 17
3 9 LOAD_CONST 1 ('ok')
12 PRINT_ITEM
13 PRINT_NEWLINE
14 JUMP_ABSOLUTE 3
>> 17 POP_BLOCK
>> 18 LOAD_CONST 0 (None)
21 RETURN_VALUE
(in Python 3, True and False are keywords so the loop prelude can be elided entirely)
Re:PHP: why GOTO instead of recursion?
by jbrooksuk on Tuesday September 23, 2014 @12:05PM
(#8356015)
I've never tried, but this (http://us2.php.net/manual/en/function.runkit-constant-redefi...) seems relevant.
Re:PHP: why GOTO instead of recursion?
by richardwhiuk on Tuesday September 23, 2014 @01:28PM
(#8356612)
So if you redefine true to false:
runkit_constant_redefine("true", false) == false in success and failure (as success results in true, which equals false now).
It has been a long time since I last wrote PHP code, but is it possible to dynamically redefine the value of `true`? That would (partially) explain why you can't statically evaluate it to `\true`.