From: Marcus Boerger Date: Mon, 4 Aug 2003 23:00:57 +0000 (+0000) Subject: Update documentation in source, reflection and docu itself X-Git-Tag: RELEASE_1_2b5~35 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=28dd8fcff288953bdde9b72731479b7fcb6902d2;p=php Update documentation in source, reflection and docu itself --- diff --git a/ext/spl/spl.php b/ext/spl/spl.php index 4f664d2ffe..42380bcbda 100755 --- a/ext/spl/spl.php +++ b/ext/spl/spl.php @@ -11,13 +11,16 @@ * 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 diff --git a/ext/spl/spl_array.c b/ext/spl/spl_array.c index d728942a49..57a38bc214 100755 --- a/ext/spl/spl_array.c +++ b/ext/spl/spl_array.c @@ -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) { diff --git a/ext/spl/spl_functions.h b/ext/spl/spl_functions.h index 3eddbe0d84..215345d594 100755 --- a/ext/spl/spl_functions.h +++ b/ext/spl/spl_functions.h @@ -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)