Skip to content

Commit f1ceec5

Browse files
committed
Fixed bug #77058
Account for the fact that undef must be interpreted as null for the purposes of INC/DEC inference.
1 parent e7153e8 commit f1ceec5

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

NEWS

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ PHP NEWS
22
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
33
?? ??? 2018, PHP 7.1.25
44

5-
5+
- Opcache:
6+
. Fixed bug #77058 (Type inference in opcache causes side effects). (Nikita)
67

78
08 Nov 2018, PHP 7.1.24
89

ext/opcache/Optimizer/zend_inference.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2434,7 +2434,7 @@ static int zend_update_type_info(const zend_op_array *op_array,
24342434
tmp |= MAY_BE_RCN;
24352435
}
24362436
}
2437-
if ((t1 & MAY_BE_ANY) == MAY_BE_LONG) {
2437+
if ((t1 & (MAY_BE_ANY|MAY_BE_UNDEF)) == MAY_BE_LONG) {
24382438
if (!ssa_var_info[ssa_ops[i].op1_use].has_range ||
24392439
(opline->opcode == ZEND_PRE_DEC &&
24402440
(ssa_var_info[ssa_ops[i].op1_use].range.underflow ||
@@ -2496,7 +2496,7 @@ static int zend_update_type_info(const zend_op_array *op_array,
24962496
if (t1 & (MAY_BE_RC1|MAY_BE_RCN)) {
24972497
tmp |= MAY_BE_RC1;
24982498
}
2499-
if ((t1 & MAY_BE_ANY) == MAY_BE_LONG) {
2499+
if ((t1 & (MAY_BE_ANY|MAY_BE_UNDEF)) == MAY_BE_LONG) {
25002500
if (!ssa_var_info[ssa_ops[i].op1_use].has_range ||
25012501
(opline->opcode == ZEND_PRE_DEC &&
25022502
(ssa_var_info[ssa_ops[i].op1_use].range.underflow ||

ext/opcache/tests/bug77058.phpt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
--TEST--
2+
Bug #77058: Type inference in opcache causes side effects
3+
--FILE--
4+
<?php
5+
6+
function myfunc(){
7+
$Nr = 0;
8+
while(1){
9+
$x--;
10+
$x++;
11+
if( ++ $Nr >= 2 ) break;
12+
}
13+
echo "'$Nr' is expected to be 2", PHP_EOL;
14+
}
15+
myfunc();
16+
17+
?>
18+
--EXPECTF--
19+
Notice: Undefined variable: x in %s on line %d
20+
'2' is expected to be 2

0 commit comments

Comments
 (0)