* 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();
}
/*! \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();
function set($index, $value) {
$this->ar[$index] = $value;
}
+ function del($index) {
+ unset($this->ar[$index]);
+ }
}
\endcode
*/
/*! 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
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}
};
}
/* }}} */
-/* {{{ 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)
{
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)