diff options
-rw-r--r-- | ext/opcache/Optimizer/dce.c | 10 | ||||
-rw-r--r-- | ext/opcache/tests/optimize_static_001.phpt | 19 |
2 files changed, 29 insertions, 0 deletions
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-- +<?php require_once('skipif.inc'); ?> +--FILE-- +<?php +function foo() { + static $a = UNDEFINED_CONST; +} +foo(); +?> +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 |