]> granicus.if.org Git - php/commitdiff
- Fix issue related to #36941 (when referencing itself)
authorMarcus Boerger <helly@php.net>
Mon, 3 Apr 2006 19:52:02 +0000 (19:52 +0000)
committerMarcus Boerger <helly@php.net>
Mon, 3 Apr 2006 19:52:02 +0000 (19:52 +0000)
ext/spl/spl_array.c
ext/spl/tests/array_022.phpt [new file with mode: 0755]

index b36a92d0719a887f2e474aff9a4f79bd383740da..3f0181dae4b855488992059f29e85055a1cd81e6 100755 (executable)
@@ -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 (executable)
index 0000000..d1eafd6
--- /dev/null
@@ -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===