Skip to content

Commit 4d0d7ce

Browse files
committed
Don't eliminate BIND_STATIC if it may cause undefined constant warning
1 parent beb58ca commit 4d0d7ce

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

ext/opcache/Optimizer/dce.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,16 @@ static inline zend_bool may_have_side_effects(
242242
}
243243
return 0;
244244
case ZEND_BIND_STATIC:
245+
if (op_array->static_variables
246+
&& (opline->extended_value & ZEND_BIND_REF) != 0) {
247+
zval *value =
248+
(zval*)((char*)op_array->static_variables->arData +
249+
(opline->extended_value & ~ZEND_BIND_REF));
250+
if (Z_TYPE_P(value) == IS_CONSTANT_AST) {
251+
/* AST may contain undefined constants */
252+
return 1;
253+
}
254+
}
245255
return 0;
246256
default:
247257
/* For everything we didn't handle, assume a side-effect */
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
--TEST--
2+
Keep BIND_STATIC when initial value refer to unresolved constants
3+
--INI--
4+
opcache.enable=1
5+
opcache.enable_cli=1
6+
opcache.optimization_level=-1
7+
--SKIPIF--
8+
<?php require_once('skipif.inc'); ?>
9+
--FILE--
10+
<?php
11+
function foo() {
12+
static $a = UNDEFINED_CONST;
13+
}
14+
foo();
15+
?>
16+
OK
17+
--EXPECTF--
18+
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
19+
OK

0 commit comments

Comments
 (0)