]> granicus.if.org Git - php/commitdiff
MFH: Fixed bug #45614 (ArrayIterator::current(), ::key() can show 1st private prop...
authorArnaud Le Blanc <lbarnaud@php.net>
Thu, 24 Jul 2008 15:54:41 +0000 (15:54 +0000)
committerArnaud Le Blanc <lbarnaud@php.net>
Thu, 24 Jul 2008 15:54:41 +0000 (15:54 +0000)
NEWS
ext/spl/spl_array.c
ext/spl/tests/bug45614.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index 12853de397ff18c4d81eab3057361bb657d78c7e..345efcb41f68a23f6febfa86881427d6d7d325b8 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -219,6 +219,8 @@ PHP                                                                        NEWS
 - Fixed PECL bug #12431 (OCI8 ping functionality is broken). (Oracle Corp.)
 - Fixed PECL bug #12401 (Add support for ATTR_FETCH_TABLE_NAMES). (Johannes)
 
+- Fixed bug #45614 (ArrayIterator::current(), ::key() can show 1st private 
+  prop of wrapped object). (robin_fernandes at uk dot ibm dot com, Arnaud)
 - Fixed bug #45571 (ReflectionClass::export() shows superclasses' private
   static methods). (robin_fernandes at uk dot ibm dot com)
 - Fixed bug #45345 (SPLFileInfo::getPathInfo() returning dir info instead of
index e4a6e3094ec745b6995ce3c35464a832bc31bde5..0dd5a5c35c2c5f2107c47da59bd2769ca05379ce 100755 (executable)
@@ -86,6 +86,8 @@ static inline HashTable *spl_array_get_hash_table(spl_array_object* intern, int
        }
 } /* }}} */
 
+static void spl_array_rewind(spl_array_object *intern TSRMLS_DC);
+
 SPL_API int spl_hash_verify_pos(spl_array_object * intern TSRMLS_DC) /* {{{ */
 {
        HashTable *ht = spl_array_get_hash_table(intern, 0 TSRMLS_CC);
@@ -102,7 +104,7 @@ SPL_API int spl_hash_verify_pos(spl_array_object * intern TSRMLS_DC) /* {{{ */
                p = p->pListNext;
        }
 /*     HASH_UNPROTECT_RECURSION(ht); */
-       zend_hash_internal_pointer_reset_ex(spl_array_get_hash_table(intern, 0 TSRMLS_CC), &intern->pos);
+       spl_array_rewind(intern TSRMLS_CC);
        return FAILURE;
 }
 /* }}} */
@@ -226,7 +228,7 @@ static zend_object_value spl_array_object_new_ex(zend_class_entry *class_type, s
                }
        }
 
-       zend_hash_internal_pointer_reset_ex(spl_array_get_hash_table(intern, 0 TSRMLS_CC), &intern->pos);
+       spl_array_rewind(intern TSRMLS_CC);
        return retval;
 }
 /* }}} */
@@ -702,8 +704,6 @@ static int spl_array_has_property(zval *object, zval *member, int has_set_exists
        return std_object_handlers.has_property(object, member, has_set_exists TSRMLS_CC);
 } /* }}} */
 
-static void spl_array_rewind(spl_array_object *intern TSRMLS_DC);
-
 static void spl_array_unset_property(zval *object, zval *member TSRMLS_DC) /* {{{ */
 {
        spl_array_object *intern = (spl_array_object*)zend_object_store_get_object(object TSRMLS_CC);
@@ -1164,7 +1164,7 @@ SPL_METHOD(Array, seek)
        opos = position;
 
        if (position >= 0) { /* negative values are not supported */
-               zend_hash_internal_pointer_reset_ex(aht, &intern->pos);
+               spl_array_rewind(intern TSRMLS_CC);
                result = SUCCESS;
                
                while (position-- > 0 && (result = spl_array_next(intern TSRMLS_CC)) == SUCCESS);
@@ -1192,7 +1192,7 @@ int static spl_array_object_count_elements_helper(spl_array_object *intern, long
                 * we're going to call and which do not support 'pos' as parameter. */
                pos = intern->pos;
                *count = 0;
-               zend_hash_internal_pointer_reset_ex(aht, &intern->pos);
+               spl_array_rewind(intern TSRMLS_CC);
                while(intern->pos && spl_array_next(intern TSRMLS_CC) == SUCCESS) {
                        (*count)++;
                }
diff --git a/ext/spl/tests/bug45614.phpt b/ext/spl/tests/bug45614.phpt
new file mode 100644 (file)
index 0000000..8f99934
--- /dev/null
@@ -0,0 +1,56 @@
+--TEST--
+SPL: Bug#45614 (ArrayIterator can show 1st private prop of wrapped object)
+--FILE--
+<?php
+class C {
+       private $priv1 = 'secret1';
+       private $priv2 = 'secret2';
+       public $pub1 = 'public1';
+       public $pub2 = 'public2';
+       public $pub3 = 'public3';
+} 
+
+function showFirstTwoItems($it) {
+  echo str_replace("\0", '\0', $it->key()) . " => " . $it->current() .
+"\n";
+  $it->next();
+  echo str_replace("\0", '\0', $it->key()) . " => " . $it->current() .
+"\n";
+}
+
+$ao = new ArrayObject(new C);
+$ai = $ao->getIterator();
+
+echo "--> Show the first two items:\n";
+showFirstTwoItems($ai);
+
+echo "\n--> Rewind and show the first two items:\n";
+$ai->rewind();
+showFirstTwoItems($ai);
+
+echo "\n--> Invalidate current position and show the first two items:\n";
+unset($ai[$ai->key()]);
+$ai->current();
+showFirstTwoItems($ai);
+
+echo "\n--> Rewind, seek and show the first two items:\n";
+$ai->rewind();
+$ai->seek(0);
+showFirstTwoItems($ai);
+?>
+--EXPECT--
+--> Show the first two items:
+pub1 => public1
+pub2 => public2
+
+--> Rewind and show the first two items:
+pub1 => public1
+pub2 => public2
+
+--> Invalidate current position and show the first two items:
+pub1 => public1
+pub3 => public3
+
+--> Rewind, seek and show the first two items:
+pub1 => public1
+pub3 => public3