Skip to content

Commit

Permalink
Fixed bug #75242
Browse files Browse the repository at this point in the history
  • Loading branch information
nikic committed Dec 22, 2017
1 parent ccb113c commit ec142f2
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 4 deletions.
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ PHP NEWS
- SPL:
. Fixed bug #75717 (RecursiveArrayIterator does not traverse arrays by
reference). (Nikita)
. Fixed bug #75242 (RecursiveArrayIterator doesn't have constants from parent
class). (Nikita)

04 Jan 2018, PHP 7.1.13

Expand Down
8 changes: 4 additions & 4 deletions ext/spl/spl_array.c
Original file line number Diff line number Diff line change
Expand Up @@ -1999,16 +1999,16 @@ PHP_MINIT_FUNCTION(spl_array)
memcpy(&spl_handler_ArrayIterator, &spl_handler_ArrayObject, sizeof(zend_object_handlers));
spl_ce_ArrayIterator->get_iterator = spl_array_get_iterator;

REGISTER_SPL_SUB_CLASS_EX(RecursiveArrayIterator, ArrayIterator, spl_array_object_new, spl_funcs_RecursiveArrayIterator);
REGISTER_SPL_IMPLEMENTS(RecursiveArrayIterator, RecursiveIterator);
spl_ce_RecursiveArrayIterator->get_iterator = spl_array_get_iterator;

REGISTER_SPL_CLASS_CONST_LONG(ArrayObject, "STD_PROP_LIST", SPL_ARRAY_STD_PROP_LIST);
REGISTER_SPL_CLASS_CONST_LONG(ArrayObject, "ARRAY_AS_PROPS", SPL_ARRAY_ARRAY_AS_PROPS);

REGISTER_SPL_CLASS_CONST_LONG(ArrayIterator, "STD_PROP_LIST", SPL_ARRAY_STD_PROP_LIST);
REGISTER_SPL_CLASS_CONST_LONG(ArrayIterator, "ARRAY_AS_PROPS", SPL_ARRAY_ARRAY_AS_PROPS);

REGISTER_SPL_SUB_CLASS_EX(RecursiveArrayIterator, ArrayIterator, spl_array_object_new, spl_funcs_RecursiveArrayIterator);
REGISTER_SPL_IMPLEMENTS(RecursiveArrayIterator, RecursiveIterator);
spl_ce_RecursiveArrayIterator->get_iterator = spl_array_get_iterator;

REGISTER_SPL_CLASS_CONST_LONG(RecursiveArrayIterator, "CHILD_ARRAYS_ONLY", SPL_ARRAY_CHILD_ARRAYS_ONLY);

return SUCCESS;
Expand Down
36 changes: 36 additions & 0 deletions ext/spl/tests/bug75242.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
--TEST--
Bug #75242: RecursiveArrayIterator doesn't have constants from parent class
--FILE--
<?php

class Foo extends ArrayIterator { }

$r = new ReflectionClass(Foo::class);
var_dump($r->getConstants());
$r = new ReflectionClass(ArrayIterator::class);
var_dump($r->getConstants());
$r = new ReflectionClass(RecursiveArrayIterator::class);
var_dump($r->getConstants());

?>
--EXPECT--
array(2) {
["STD_PROP_LIST"]=>
int(1)
["ARRAY_AS_PROPS"]=>
int(2)
}
array(2) {
["STD_PROP_LIST"]=>
int(1)
["ARRAY_AS_PROPS"]=>
int(2)
}
array(3) {
["STD_PROP_LIST"]=>
int(1)
["ARRAY_AS_PROPS"]=>
int(2)
["CHILD_ARRAYS_ONLY"]=>
int(4)
}

0 comments on commit ec142f2

Please sign in to comment.