]> granicus.if.org Git - php/commitdiff
Update documentation in source, reflection and docu itself
authorMarcus Boerger <helly@php.net>
Mon, 4 Aug 2003 23:00:57 +0000 (23:00 +0000)
committerMarcus Boerger <helly@php.net>
Mon, 4 Aug 2003 23:00:57 +0000 (23:00 +0000)
ext/spl/spl.php
ext/spl/spl_array.c
ext/spl/spl_functions.h

index 4f664d2ffebd8cd118120e42d041aa623da93ec8..42380bcbda2a2aafaaa4d5faf85b289ad638ab54 100755 (executable)
  * the input parameter to foreach() calls which would normally be an 
  * array.
  *
- * The only thing a class has to do is 
+ * The class must implement the function new_iterator which must return 
+ * an object which implements the interface spl_forward.
+ *
+ * \see spl_forward, spl_sequence, spl_forward_assoc, spl_sequence_assoc
  */
 interface spl_iterator {
        
        /*! \brief Create a new iterator
         *
-        * used for example in foreach() operator.
+        * \return an object that implements the interface spl_forward.
         */
        function new_iterator();
 }
@@ -217,7 +220,7 @@ interface spl_array_read {
 
 /*! \brief array read/write access for objects.
  *
- * The following example shows how to use an array_writer:
+ * The following example shows how to use interface array_access:
  * \code 
        class array_emulation implemets spl_array_access {
                private $ar = array();
@@ -230,6 +233,9 @@ interface spl_array_read {
                function set($index, $value) {
                        $this->ar[$index] = $value;
                }
+               function del($index) {
+                       unset($this->ar[$index]);
+               }
        }
    \endcode
  */
@@ -237,7 +243,68 @@ interface spl_array_access implements spl_array_read {
 
        /*! Set the value identified by $index to $value.
         */
-       function set($value, $index);
+       function set($index, $value);
+
+       /*! Delete (unset) the value identified by $index.
+        */
+       function del($index);
+}
+
+/*! \brief An array wrapper
+ *
+ * This array wrapper allows to recursively iterate over Arrays and Objects.
+ *
+ * \see spl_array_it
+ */
+class spl_array implements spl_iterator {
+
+       /*! Construct a new array iterator from anything that has a hash table.
+        * That is any Array or Object.
+        *
+        * \param $array the array to use.
+        */
+       function __construct($array);
+
+       /*! \copydoc spl_iterator::new_iterator
+        */
+       function new_iterator();
+}
+
+/*! \brief An array iterator
+ *
+ * This iterator allows to unset and modify values and keys while iterating
+ * over Arrays and Objects.
+ *
+ * To use this class you must instanciate spl_array.
+ */
+class spl_array_it implements spl_sequence_assoc {
+
+       /*! Construct a new array iterator from anything that has a hash table.
+        * That is any Array or Object.
+        *
+        * \param $array the array to use.
+        */
+       private function __construct($array)
+
+       /*! \copydoc spl_sequence::rewind
+        */
+       function rewind()
+
+       /*! \copydoc spl_forward::current
+        */
+       function current()
+
+       /*! \copydoc spl_assoc::key
+        */
+       function key()
+
+       /*! \copydoc spl_forward::next
+        */
+       function next()
+
+       /*! \copydoc spl_forward::has_more
+        */
+       function has_more()
 }
 
 ?>
\ No newline at end of file
index d728942a49f822fd21bad4e4d9de8f195e010fea..57a38bc21464bed68749a791d377fee41bf5b34e 100755 (executable)
@@ -308,19 +308,24 @@ SPL_CLASS_FUNCTION(array, key);
 SPL_CLASS_FUNCTION(array, next);
 SPL_CLASS_FUNCTION(array, has_more);
 
+static
+ZEND_BEGIN_ARG_INFO(arginfo_array___construct, 0)
+       ZEND_ARG_INFO(0, array)
+ZEND_END_ARG_INFO();
+
 static zend_function_entry spl_array_class_functions[] = {
-       SPL_CLASS_FE(array, __construct,   NULL)
-       SPL_CLASS_FE(array, new_iterator,  NULL)
+       SPL_CLASS_FE(array, __construct,   arginfo_array___construct, ZEND_ACC_PUBLIC)
+       SPL_CLASS_FE(array, new_iterator,  NULL, ZEND_ACC_PUBLIC)
        {NULL, NULL, NULL}
 };
 
 static zend_function_entry spl_array_it_class_functions[] = {
-       SPL_CLASS_FE(array, __construct,   NULL)
-       SPL_CLASS_FE(array, rewind,        NULL)
-       SPL_CLASS_FE(array, current,       NULL)
-       SPL_CLASS_FE(array, key,           NULL)
-       SPL_CLASS_FE(array, next,          NULL)
-       SPL_CLASS_FE(array, has_more,      NULL)
+       SPL_CLASS_FE(array, __construct,   arginfo_array___construct, ZEND_ACC_PRIVATE)
+       SPL_CLASS_FE(array, rewind,        NULL, ZEND_ACC_PUBLIC)
+       SPL_CLASS_FE(array, current,       NULL, ZEND_ACC_PUBLIC)
+       SPL_CLASS_FE(array, key,           NULL, ZEND_ACC_PUBLIC)
+       SPL_CLASS_FE(array, next,          NULL, ZEND_ACC_PUBLIC)
+       SPL_CLASS_FE(array, has_more,      NULL, ZEND_ACC_PUBLIC)
        {NULL, NULL, NULL}
 };
 
@@ -558,8 +563,8 @@ PHP_MINIT_FUNCTION(spl_array)
 }
 /* }}} */
 
-/* {{{ proto void spl_array::__construct(array ar = array())
-       proto void spl_array_it::__construct(array ar = array())
+/* {{{ proto void spl_array::__construct(array|object ar = array())
+       proto void spl_array_it::__construct(array|object ar = array())
  Cronstructs a new array iterator from a path. */
 SPL_CLASS_FUNCTION(array, __construct)
 {
index 3eddbe0d84825f34ecc4ec945a515a23a20f9c84..215345d59413e7639cd7d08a93cfc0ee5b431315 100755 (executable)
@@ -59,8 +59,8 @@ void spl_add_class_name(zval * list, zend_class_entry * pce TSRMLS_DC);
 void spl_add_interfaces(zval * list, zend_class_entry * pce TSRMLS_DC);
 int spl_add_classes(zend_class_entry ** ppce, zval *list TSRMLS_DC);
 
-#define SPL_CLASS_FE(class_name, function_name, arg_types) \
-       PHP_NAMED_FE( function_name, spl_ ## class_name ## _ ## function_name, arg_types)
+#define SPL_CLASS_FE(class_name, function_name, arg_info, flags) \
+       { #function_name, spl_ ## class_name ## _ ## function_name, arg_info, sizeof(arg_info)/sizeof(struct _zend_arg_info)-1, flags },
 
 #define SPL_CLASS_FUNCTION(class_name, function_name) \
        PHP_NAMED_FUNCTION(spl_ ## class_name ## _ ## function_name)