Skip to content

Commit 4576da0

Browse files
committed
Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3: Fix #79393: Null coalescing operator failing with SplFixedArray
2 parents db08ef0 + 47c7455 commit 4576da0

File tree

3 files changed

+31
-13
lines changed

3 files changed

+31
-13
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ PHP NEWS
2323

2424
- Spl:
2525
. Fixed bug #75673 (SplStack::unserialize() behavior). (cmb)
26+
. Fixed bug #79393 (Null coalescing operator failing with SplFixedArray).
27+
(cmb)
2628

2729
- Zip:
2830
. Fixed Bug #79296 (ZipArchive::open fails on empty file). (Remi)

ext/spl/spl_fixedarray.c

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -337,25 +337,16 @@ static inline zval *spl_fixedarray_object_read_dimension_helper(spl_fixedarray_o
337337
}
338338
/* }}} */
339339

340+
static int spl_fixedarray_object_has_dimension(zval *object, zval *offset, int check_empty);
341+
340342
static zval *spl_fixedarray_object_read_dimension(zval *object, zval *offset, int type, zval *rv) /* {{{ */
341343
{
342344
spl_fixedarray_object *intern;
343345

344346
intern = Z_SPLFIXEDARRAY_P(object);
345347

346-
if (type == BP_VAR_IS && intern->fptr_offset_has) {
347-
SEPARATE_ARG_IF_REF(offset);
348-
zend_call_method_with_1_params(object, intern->std.ce, &intern->fptr_offset_has, "offsetexists", rv, offset);
349-
if (UNEXPECTED(Z_ISUNDEF_P(rv))) {
350-
zval_ptr_dtor(offset);
351-
return NULL;
352-
}
353-
if (!i_zend_is_true(rv)) {
354-
zval_ptr_dtor(offset);
355-
zval_ptr_dtor(rv);
356-
return &EG(uninitialized_zval);
357-
}
358-
zval_ptr_dtor(rv);
348+
if (type == BP_VAR_IS && !spl_fixedarray_object_has_dimension(object, offset, 0)) {
349+
return &EG(uninitialized_zval);
359350
}
360351

361352
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)