From: Xinchen Hui Date: Tue, 20 Dec 2016 13:01:21 +0000 (+0800) Subject: Fixed bug #73789 (Strange behavior of class constants in switch/case block) X-Git-Tag: php-7.1.1RC1~71 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6bd41a1d47417ad2c7938a57c8abca4e210d5cf6;p=php Fixed bug #73789 (Strange behavior of class constants in switch/case block) --- diff --git a/NEWS b/NEWS index 9e1cbf2b11..f94dd9aa9c 100644 --- a/NEWS +++ b/NEWS @@ -26,6 +26,8 @@ PHP NEWS usage. (Andrey) - Opcache: + . Fixed bug #73789 (Strange behavior of class constants in switch/case block). + (Laruence) . Fixed bug #73746 (Method that returns string returns UNKNOWN:0 instead). (Laruence) . Fixed bug #73654 (Segmentation fault in zend_call_function). (Nikita) diff --git a/ext/opcache/Optimizer/dfa_pass.c b/ext/opcache/Optimizer/dfa_pass.c index b7a0f065f7..2780a4cc54 100644 --- a/ext/opcache/Optimizer/dfa_pass.c +++ b/ext/opcache/Optimizer/dfa_pass.c @@ -569,19 +569,23 @@ void zend_dfa_optimize_op_array(zend_op_array *op_array, zend_optimizer_ctx *ctx // op_1: VERIFY_RETURN_TYPE #orig_var.CV [T] -> #v.CV [T] => NOP int orig_var = ssa->ops[op_1].op1_use; - int ret = ssa->vars[v].use_chain; + if (zend_ssa_unlink_use_chain(ssa, op_1, orig_var)) { - ssa->vars[orig_var].use_chain = ret; - ssa->ops[ret].op1_use = orig_var; + int ret = ssa->vars[v].use_chain; - ssa->vars[v].definition = -1; - ssa->vars[v].use_chain = -1; + ssa->ops[ret].op1_use = orig_var; + ssa->ops[ret].op1_use_chain = ssa->vars[orig_var].use_chain; + ssa->vars[orig_var].use_chain = ret; - ssa->ops[op_1].op1_def = -1; - ssa->ops[op_1].op1_use = -1; + ssa->vars[v].definition = -1; + ssa->vars[v].use_chain = -1; + + ssa->ops[op_1].op1_def = -1; + ssa->ops[op_1].op1_use = -1; - MAKE_NOP(opline); - remove_nops = 1; + MAKE_NOP(opline); + remove_nops = 1; + } } else if (ssa->ops[op_1].op1_def == v && !RETURN_VALUE_USED(opline) diff --git a/ext/opcache/tests/bug73789.phpt b/ext/opcache/tests/bug73789.phpt new file mode 100644 index 0000000000..142d5229f9 --- /dev/null +++ b/ext/opcache/tests/bug73789.phpt @@ -0,0 +1,30 @@ +--TEST-- +Bug #73789 (Strange behavior of class constants in switch/case block) +--FILE-- + 100) { + return $type; + } + return self::T_STRING; + case $value === '.': + return self::T_DOT; + default: + } + return $type; + } +} +var_dump((new Lexer())->getType("dot")); +--EXPECT-- +int(2)