Skip to content

Commit

Permalink
Fixed bug #62059
Browse files Browse the repository at this point in the history
  • Loading branch information
nikic committed Mar 20, 2016
1 parent 12f2665 commit f330917
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 6 deletions.
1 change: 1 addition & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ PHP NEWS
. Fixed bug #71731 (Null coalescing operator and ArrayAccess). (Nikita)
. Fixed bug #69659 (ArrayAccess, isset() and the offsetExists method).
(Nikita)
. Fixed bug #62059 (ArrayObject and isset are not friends). (Nikita)

- ODBC:
. Fixed bug #63171 (Script hangs after max_execution_time). (Remi)
Expand Down
21 changes: 15 additions & 6 deletions ext/spl/spl_array.c
Original file line number Diff line number Diff line change
Expand Up @@ -275,12 +275,11 @@ static zend_object *spl_array_object_clone(zval *zobject)
}
/* }}} */

static zval *spl_array_get_dimension_ptr(int check_inherited, zval *object, zval *offset, int type) /* {{{ */
static zval *spl_array_get_dimension_ptr(int check_inherited, spl_array_object *intern, zval *offset, int type) /* {{{ */
{
zval *retval;
zend_long index;
zend_string *offset_key;
spl_array_object *intern = Z_SPLARRAY_P(object);
HashTable *ht = spl_array_get_hash_table(intern);

if (!offset || Z_ISUNDEF_P(offset)) {
Expand Down Expand Up @@ -382,12 +381,21 @@ static zval *spl_array_get_dimension_ptr(int check_inherited, zval *object, zval
}
} /* }}} */

static int spl_array_has_dimension(zval *object, zval *offset, int check_empty);

static zval *spl_array_read_dimension_ex(int check_inherited, zval *object, zval *offset, int type, zval *rv) /* {{{ */
{
spl_array_object *intern = Z_SPLARRAY_P(object);
zval *ret;

if (check_inherited) {
spl_array_object *intern = Z_SPLARRAY_P(object);
if (check_inherited &&
(intern->fptr_offset_get || (type == BP_VAR_IS && intern->fptr_offset_has))) {
if (type == BP_VAR_IS) {
if (!spl_array_has_dimension(object, offset, 0)) {
return &EG(uninitialized_zval);
}
}

if (intern->fptr_offset_get) {
zval tmp;
if (!offset) {
Expand All @@ -405,7 +413,8 @@ static zval *spl_array_read_dimension_ex(int check_inherited, zval *object, zval
return &EG(uninitialized_zval);
}
}
ret = spl_array_get_dimension_ptr(check_inherited, object, offset, type);

ret = spl_array_get_dimension_ptr(check_inherited, intern, offset, type);

/* When in a write context,
* ZE has to be fooled into thinking this is in a reference set
Expand Down Expand Up @@ -879,7 +888,7 @@ static zval *spl_array_get_property_ptr_ptr(zval *object, zval *member, int type

if ((intern->ar_flags & SPL_ARRAY_ARRAY_AS_PROPS) != 0
&& !std_object_handlers.has_property(object, member, 2, NULL)) {
return spl_array_get_dimension_ptr(1, object, member, type);
return spl_array_get_dimension_ptr(1, intern, member, type);
}
return std_object_handlers.get_property_ptr_ptr(object, member, type, cache_slot);
} /* }}} */
Expand Down
70 changes: 70 additions & 0 deletions ext/spl/tests/bug62059.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
--TEST--
Bug #62059: ArrayObject and isset are not friends
--FILE--
<?php

class MyArrayObject1 extends ArrayObject {
public function offsetGet($name) {
echo "offsetGet($name)\n";
return parent::offsetGet($name);
}
public function offsetExists($name) {
echo "offsetExists($name)\n";
return parent::offsetExists($name);
}
}
class MyArrayObject2 extends ArrayObject {
public function offsetGet($name) {
echo "offsetGet($name)\n";
return parent::offsetGet($name);
}
}
class MyArrayObject3 extends ArrayObject {
public function offsetExists($name) {
echo "offsetExists($name)\n";
return parent::offsetExists($name);
}
}

$arr = [1 => [1 => 42]];
$ao = new ArrayObject($arr);
var_dump(isset($ao[0][1]));
var_dump(isset($ao[1][0]));
var_dump(isset($ao[1][1]));
$ao = new MyArrayObject1($arr);
var_dump(isset($ao[0][1]));
var_dump(isset($ao[1][0]));
var_dump(isset($ao[1][1]));
$ao = new MyArrayObject2($arr);
var_dump(isset($ao[0][1]));
var_dump(isset($ao[1][0]));
var_dump(isset($ao[1][1]));
$ao = new MyArrayObject3($arr);
var_dump(isset($ao[0][1]));
var_dump(isset($ao[1][0]));
var_dump(isset($ao[1][1]));

?>
--EXPECT--
bool(false)
bool(false)
bool(true)
offsetExists(0)
bool(false)
offsetExists(1)
offsetGet(1)
bool(false)
offsetExists(1)
offsetGet(1)
bool(true)
bool(false)
offsetGet(1)
bool(false)
offsetGet(1)
bool(true)
offsetExists(0)
bool(false)
offsetExists(1)
bool(false)
offsetExists(1)
bool(true)

0 comments on commit f330917

Please sign in to comment.