Skip to content

Commit f48ab6a

Browse files
committed
Fixed GH-12747: Function JIT returns invalid error message for coalesce operator on invalid offset
1 parent af155cf commit f48ab6a

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

ext/opcache/jit/zend_jit_helpers.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,9 @@ static void ZEND_FASTCALL zend_jit_fetch_dim_is_helper(zend_array *ht, zval *dim
620620
hval = 1;
621621
goto num_index;
622622
default:
623-
zend_illegal_container_offset(ZSTR_KNOWN(ZEND_STR_ARRAY), dim, BP_VAR_IS);
623+
zend_illegal_container_offset(ZSTR_KNOWN(ZEND_STR_ARRAY), dim,
624+
EG(current_execute_data)->opline->opcode == ZEND_ISSET_ISEMPTY_DIM_OBJ ?
625+
BP_VAR_IS : BP_VAR_RW);
624626
undef_result_after_exception();
625627
return;
626628
}

ext/opcache/tests/jit/gh12747.phpt

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
--TEST--
2+
GH-12747: Function JIT returns invalid error message for coalesce operator on invalid offset
3+
--INI--
4+
opcache.enable=1
5+
opcache.enable_cli=1
6+
--FILE--
7+
<?php
8+
$container = [];
9+
// Is
10+
try {
11+
echo "isset():\n";
12+
var_dump(isset($container[new stdClass()]));
13+
} catch (\Throwable $e) {
14+
echo $e->getMessage(), "\n";
15+
}
16+
try {
17+
echo "empty():\n";
18+
var_dump(empty($container[new stdClass()]));
19+
} catch (\Throwable $e) {
20+
echo $e->getMessage(), "\n";
21+
}
22+
try {
23+
echo "Coalesce():\n";
24+
var_dump($container[new stdClass()] ?? 'default');
25+
} catch (\Throwable $e) {
26+
echo $e->getMessage(), "\n";
27+
}
28+
?>
29+
--EXPECT--
30+
isset():
31+
Cannot access offset of type stdClass in isset or empty
32+
empty():
33+
Cannot access offset of type stdClass in isset or empty
34+
Coalesce():
35+
Cannot access offset of type stdClass on array

0 commit comments

Comments
 (0)