Skip to content

Commit 13467bd

Browse files
committed
Merge branch 'PHP-8.0'
* PHP-8.0: Fixed bug #81015
2 parents 779fe8e + dd3e56b commit 13467bd

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

Zend/Optimizer/zend_ssa.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,14 @@ static void place_essa_pis(
284284
default:
285285
continue;
286286
}
287+
288+
/* The following patterns all inspect the opline directly before the JMPZ opcode.
289+
* Make sure that it is part of the same block, otherwise it might not be a dominating
290+
* assignment. */
291+
if (blocks[j].len == 1) {
292+
continue;
293+
}
294+
287295
if (opline->op1_type == IS_TMP_VAR &&
288296
((opline-1)->opcode == ZEND_IS_EQUAL ||
289297
(opline-1)->opcode == ZEND_IS_NOT_EQUAL ||

ext/opcache/tests/bug81015.phpt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
--TEST--
2+
Bug #81015: Opcache optimization assumes wrong part of ternary operator in if-condition
3+
--FILE--
4+
<?php
5+
6+
function ternary(bool $enabled, ?string $value): void
7+
{
8+
// the "true" part is not as trivial in the real case
9+
if ($enabled ? true : $value === null) {
10+
echo ($value ?? 'NULL') . "\n";
11+
} else {
12+
echo "INVALID\n";
13+
}
14+
}
15+
16+
ternary(true, 'value');
17+
ternary(true, null);
18+
ternary(false, 'value');
19+
ternary(false, null);
20+
21+
?>
22+
--EXPECT--
23+
value
24+
NULL
25+
INVALID
26+
NULL

0 commit comments

Comments
 (0)