Skip to content

Commit

Permalink
Fixed bug #74478
Browse files Browse the repository at this point in the history
jhdxr authored and nikic committed May 24, 2017
1 parent fff1cab commit 872e43d
Showing 3 changed files with 80 additions and 1 deletion.
4 changes: 3 additions & 1 deletion NEWS
Original file line number Diff line number Diff line change
@@ -2,7 +2,9 @@ PHP NEWS
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
?? ??? 2017 PHP 7.0.21


- SPL:
. Fixed bug #74478 (null coalescing operator failing with SplFixedArray).
(jhdxr)

8 Jun 2017 PHP 7.0.20

15 changes: 15 additions & 0 deletions ext/spl/spl_fixedarray.c
Original file line number Diff line number Diff line change
@@ -358,6 +358,21 @@ static zval *spl_fixedarray_object_read_dimension(zval *object, zval *offset, in

intern = Z_SPLFIXEDARRAY_P(object);

if (type == BP_VAR_IS && intern->fptr_offset_has) {
SEPARATE_ARG_IF_REF(offset);
zend_call_method_with_1_params(object, intern->std.ce, &intern->fptr_offset_has, "offsetexists", rv, offset);
if (UNEXPECTED(Z_ISUNDEF_P(rv))) {
zval_ptr_dtor(offset);
return NULL;
}
if (!i_zend_is_true(rv)) {
zval_ptr_dtor(offset);
zval_ptr_dtor(rv);
return &EG(uninitialized_zval);
}
zval_ptr_dtor(rv);
}

if (intern->fptr_offset_get) {
zval tmp;
if (!offset) {
62 changes: 62 additions & 0 deletions ext/spl/tests/bug74478.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
--TEST--
Bug #74478: null coalescing operator failing with SplFixedArray
--FILE--
<?php

class MyFixedArray extends \SplFixedArray
{
public function offsetExists($name) {
echo "offsetExists($name)\n";
return parent::offsetExists($name);
}
public function offsetGet($name) {
echo "offsetGet($name)\n";
return parent::offsetGet($name);
}
public function offsetSet($name, $value) {
echo "offsetSet($name)\n";
return parent::offsetSet($name, $value);
}
public function offsetUnset($name) {
echo "offsetUnset($name)\n";
return parent::offsetUnset($name);
}

};

$fixedData = new MyFixedArray(10);
var_dump(isset($fixedData[0][1][2]));
var_dump(isset($fixedData[0]->foo));
var_dump($fixedData[0] ?? 42);
var_dump($fixedData[0][1][2] ?? 42);

$fixedData[0] = new MyFixedArray(10);
$fixedData[0][1] = new MyFixedArray(10);
var_dump(isset($fixedData[0][1][2]));
var_dump($fixedData[0][1][2] ?? 42);

?>
--EXPECT--
offsetExists(0)
bool(false)
offsetExists(0)
bool(false)
offsetExists(0)
int(42)
offsetExists(0)
int(42)
offsetSet(0)
offsetGet(0)
offsetSet(1)
offsetExists(0)
offsetGet(0)
offsetExists(1)
offsetGet(1)
offsetExists(2)
bool(false)
offsetExists(0)
offsetGet(0)
offsetExists(1)
offsetGet(1)
offsetExists(2)
int(42)

0 comments on commit 872e43d

Please sign in to comment.