diff options
-rwxr-xr-x | ext/spl/spl_array.c | 4 | ||||
-rwxr-xr-x | ext/spl/tests/array_022.phpt | 94 |
2 files changed, 97 insertions, 1 deletions
diff --git a/ext/spl/spl_array.c b/ext/spl/spl_array.c index b36a92d071..3f0181dae4 100755 --- a/ext/spl/spl_array.c +++ b/ext/spl/spl_array.c @@ -73,7 +73,9 @@ typedef struct _spl_array_object { } spl_array_object; static inline HashTable *spl_array_get_hash_table(spl_array_object* intern, int check_std_props TSRMLS_DC) { - if ((intern->ar_flags & SPL_ARRAY_USE_OTHER) && (check_std_props == 0 || (intern->ar_flags & SPL_ARRAY_STD_PROP_LIST) == 0)) { + if ((intern->ar_flags & SPL_ARRAY_IS_SELF) != 0) { + return intern->std.properties; + } else if ((intern->ar_flags & SPL_ARRAY_USE_OTHER) && (check_std_props == 0 || (intern->ar_flags & SPL_ARRAY_STD_PROP_LIST) == 0)) { spl_array_object *other = (spl_array_object*)zend_object_store_get_object(intern->array TSRMLS_CC); return spl_array_get_hash_table(other, check_std_props TSRMLS_CC); } else if ((intern->ar_flags & ((check_std_props ? SPL_ARRAY_STD_PROP_LIST : 0) | SPL_ARRAY_IS_SELF)) != 0) { diff --git a/ext/spl/tests/array_022.phpt b/ext/spl/tests/array_022.phpt new file mode 100755 index 0000000000..d1eafd677c --- /dev/null +++ b/ext/spl/tests/array_022.phpt @@ -0,0 +1,94 @@ +--TEST-- +SPL: ArrayObject/Iterator and reference to self +--FILE-- +==ArrayObject=== +<?php + +class MyArrayObject extends ArrayObject +{ + public function __construct() + { + parent::__construct($this); + $this['bar'] = 'baz'; + } +} + +$a = new MyArrayObject; + +$b = clone $a; +$b['baz'] = 'Foo'; + +var_dump($a); +var_dump($b); + +?> +==ArrayIterator=== +<?php + +class MyArrayIterator extends ArrayIterator +{ + public function __construct() + { + parent::__construct($this); + $this['bar'] = 'baz'; + } +} + +$a = new MyArrayIterator; + +$b = clone $a; +$b['baz'] = 'Foo'; + +var_dump($a); +var_dump($b); + +?> +===DONE=== +--EXPECTF-- +==ArrayObject=== +object(MyArrayObject)#%d (1) { + ["bar"]=> + string(3) "baz" +} +object(MyArrayObject)#%d (2) { + ["bar"]=> + string(3) "baz" + ["baz"]=> + string(3) "Foo" +} +==ArrayIterator=== +object(MyArrayIterator)#%d (1) { + ["bar"]=> + string(3) "baz" +} +object(MyArrayIterator)#%d (2) { + ["bar"]=> + string(3) "baz" + ["baz"]=> + string(3) "Foo" +} +===DONE=== +--UEXPECTF-- +==ArrayObject=== +object(MyArrayObject)#%d (1) { + [u"bar"]=> + unicode(3) "baz" +} +object(MyArrayObject)#%d (2) { + [u"bar"]=> + unicode(3) "baz" + [u"baz"]=> + unicode(3) "Foo" +} +==ArrayIterator=== +object(MyArrayIterator)#%d (1) { + [u"bar"]=> + unicode(3) "baz" +} +object(MyArrayIterator)#%d (2) { + [u"bar"]=> + unicode(3) "baz" + [u"baz"]=> + unicode(3) "Foo" +} +===DONE=== |