Skip to content

Commit 47c7455

Browse files
committed
Fix #79393: Null coalescing operator failing with SplFixedArray
We favor the KISS principle over optimization[1] – SPL is already special enough. [1] <https://github.com/php/php-src/pull/2489/commits/352f3d4476a79bb86136b431719df7394e5a8d4e#r112498098>ff
1 parent 51c57a9 commit 47c7455

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
@@ -18,6 +18,8 @@ PHP NEWS
1818

1919
- Spl:
2020
. Fixed bug #75673 (SplStack::unserialize() behavior). (cmb)
21+
. Fixed bug #79393 (Null coalescing operator failing with SplFixedArray).
22+
(cmb)
2123

2224
- Zip:
2325
. 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
@@ -336,25 +336,16 @@ static inline zval *spl_fixedarray_object_read_dimension_helper(spl_fixedarray_o
336336
}
337337
/* }}} */
338338

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

343345
intern = Z_SPLFIXEDARRAY_P(object);
344346

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

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