4 ms·
From the reply: "This requires doing a namespace lookup against igorw\true". It has been a long time since I last wrote PHP code, but is it possible to dynamic
by psuter 12y ago
From the reply: "This requires doing a namespace lookup against igorw\true".
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`.
- jbrooksuk 12y agoI've never tried, but this (http://us2.php.net/manual/en/function.runkit-constant-redefine.php http://us2.php.net/manual/en/function.runkit-constant-redefi...) seems relevant.
- richardwhiuk 12y agoSo 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).
- masklinn 12y ago> 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)