Skip to content

Commit bdb63a3

Browse files
committed
Merge branch 'PHP-7.4'
* PHP-7.4: Fix #79393: Null coalescing operator failing with SplFixedArray
2 parents fe88d23 + 4576da0 commit bdb63a3

File tree

2 files changed

+29
-13
lines changed

2 files changed

+29
-13
lines changed

ext/spl/spl_fixedarray.c

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -333,25 +333,16 @@ static inline zval *spl_fixedarray_object_read_dimension_helper(spl_fixedarray_o
333333
}
334334
/* }}} */
335335

336+
static int spl_fixedarray_object_has_dimension(zend_object *object, zval *offset, int check_empty);
337+
336338
static zval *spl_fixedarray_object_read_dimension(zend_object *object, zval *offset, int type, zval *rv) /* {{{ */
337339
{
338340
spl_fixedarray_object *intern;
339341

340342
intern = spl_fixed_array_from_obj(object);
341343

342-
if (type == BP_VAR_IS && intern->fptr_offset_has) {
343-
SEPARATE_ARG_IF_REF(offset);
344-
zend_call_method_with_1_params(object, intern->std.ce, &intern->fptr_offset_has, "offsetexists", rv, offset);
345-
if (UNEXPECTED(Z_ISUNDEF_P(rv))) {
346-
zval_ptr_dtor(offset);
347-
return NULL;
348-
}
349-
if (!i_zend_is_true(rv)) {
350-
zval_ptr_dtor(offset);
351-
zval_ptr_dtor(rv);
352-
return &EG(uninitialized_zval);
353-
}
354-
zval_ptr_dtor(rv);
344+
if (type == BP_VAR_IS && !spl_fixedarray_object_has_dimension(object, offset, 0)) {
345+
return &EG(uninitialized_zval);
355346
}
356347

357348
if (intern->fptr_offset_get) {

ext/spl/tests/bug79393.phpt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
--TEST--
2+
Bug #79393 (Null coalescing operator failing with SplFixedArray)
3+
--FILE--
4+
<?php
5+
$foo = new SplFixedArray(5);
6+
$foo[0] = 'bar1';
7+
$foo[1] = 'bar2';
8+
$foo[2] = 0;
9+
$foo[3] = false;
10+
$foo[4] = '';
11+
12+
var_dump($foo[0] ?? null);
13+
var_dump($foo[1] ?? null);
14+
var_dump($foo[2] ?? null);
15+
var_dump($foo[3] ?? null);
16+
var_dump($foo[4] ?? null);
17+
var_dump($foo[5] ?? null);
18+
?>
19+
--EXPECT--
20+
string(4) "bar1"
21+
string(4) "bar2"
22+
int(0)
23+
bool(false)
24+
string(0) ""
25+
NULL

0 commit comments

Comments
 (0)