]> granicus.if.org Git - php/commitdiff
Don't eliminate BIND_STATIC if it may cause undefined constant warning
authorDmitry Stogov <dmitry@zend.com>
Tue, 23 Apr 2019 19:39:14 +0000 (22:39 +0300)
committerDmitry Stogov <dmitry@zend.com>
Tue, 23 Apr 2019 19:39:14 +0000 (22:39 +0300)
ext/opcache/Optimizer/dce.c
ext/opcache/tests/optimize_static_001.phpt [new file with mode: 0644]

index bd3b60ac65def79852f723788a2c822c63094048..c9ef7111cab7c167f4ac4ea64c582e63e298d687 100644 (file)
@@ -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 (file)
index 0000000..d4e2c58
--- /dev/null
@@ -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