From: Dmitry Stogov Date: Tue, 23 Apr 2019 19:39:14 +0000 (+0300) Subject: Don't eliminate BIND_STATIC if it may cause undefined constant warning X-Git-Tag: php-7.4.0alpha1~425 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4d0d7ce34955264366eaa51a0c93fe1e7314685e;p=php Don't eliminate BIND_STATIC if it may cause undefined constant warning --- diff --git a/ext/opcache/Optimizer/dce.c b/ext/opcache/Optimizer/dce.c index bd3b60ac65..c9ef7111ca 100644 --- a/ext/opcache/Optimizer/dce.c +++ b/ext/opcache/Optimizer/dce.c @@ -242,6 +242,16 @@ static inline zend_bool may_have_side_effects( } return 0; case ZEND_BIND_STATIC: + if (op_array->static_variables + && (opline->extended_value & ZEND_BIND_REF) != 0) { + zval *value = + (zval*)((char*)op_array->static_variables->arData + + (opline->extended_value & ~ZEND_BIND_REF)); + if (Z_TYPE_P(value) == IS_CONSTANT_AST) { + /* AST may contain undefined constants */ + return 1; + } + } return 0; default: /* For everything we didn't handle, assume a side-effect */ diff --git a/ext/opcache/tests/optimize_static_001.phpt b/ext/opcache/tests/optimize_static_001.phpt new file mode 100644 index 0000000000..d4e2c58062 --- /dev/null +++ b/ext/opcache/tests/optimize_static_001.phpt @@ -0,0 +1,19 @@ +--TEST-- +Keep BIND_STATIC when initial value refer to unresolved constants +--INI-- +opcache.enable=1 +opcache.enable_cli=1 +opcache.optimization_level=-1 +--SKIPIF-- + +--FILE-- + +OK +--EXPECTF-- +Warning: Use of undefined constant UNDEFINED_CONST - assumed 'UNDEFINED_CONST' (this will throw an Error in a future version of PHP) in %s on line %d +OK \ No newline at end of file