diff options
author | Dmitry Stogov <dmitry@zend.com> | 2019-04-23 22:39:14 +0300 |
---|---|---|
committer | Dmitry Stogov <dmitry@zend.com> | 2019-04-23 22:39:14 +0300 |
commit | 4d0d7ce34955264366eaa51a0c93fe1e7314685e (patch) | |
tree | 9b8582b52951ce2f5874f70502e025352bdd70f0 | |
parent | beb58ca128e78bdbf56956e52a87eb943d85e534 (diff) | |
download | php-git-4d0d7ce34955264366eaa51a0c93fe1e7314685e.tar.gz |
Don't eliminate BIND_STATIC if it may cause undefined constant warning
-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 |