Hello Andi,
damn, yeah, it was already to early in the morning when i sent the mail, i
somehow didn't notice that i was trying to send a '.tx' file :-(
Friday, July 4, 2003, 11:55:01 AM, you wrote:
AG> You forgot to attach the diff :)
AG> Andi
AG> At 03:56 AM 4/7/2003 +0200, Marcus Börger wrote:
>>Hello internals,
>>
>> during my todays work i was again reminded that still one array function is
>>missing namely array_has_more. This function will return true if there are
>>more elements in an array and false if not. The real problem is that next()
>>doesn't work with false.
>>
>>A diff against PHP 5 is attached. If noone objects i'll commit this later on
>>friday.
>>
>>Examle:
>><?php
>>
>>$ar = array(2,1,false,0);
>>$i = 0;
>>
>>function show() {
>> global $ar, $i;
>>
>> echo "loop: ";var_dump($i++);
>> echo "curr: ";var_dump(current($ar));
>> echo "more: ";var_dump(array_has_more($ar));
>> echo "curr: ";var_dump(current($ar));
>> echo "next: ";var_dump(next($ar));
>> echo "\n";
>>}
>>
>>show();
>>show();
>>show();
>>show();
>>show();
>>show();
>>
>>?>
>>
>>--
>>Best regards,
>> Marcus mailto:[EMAIL PROTECTED]
>>--
>>PHP Internals - PHP Runtime Development Mailing List
>>To unsubscribe, visit: http://www.php.net/unsub.php
--
Best regards,
Marcus mailto:[EMAIL PROTECTED]
Index: ext/standard/basic_functions.c
===================================================================
RCS file: /repository/php-src/ext/standard/basic_functions.c,v
retrieving revision 1.616
diff -u -p -r1.616 basic_functions.c
--- ext/standard/basic_functions.c 28 Jun 2003 05:38:52 -0000 1.616
+++ ext/standard/basic_functions.c 4 Jul 2003 01:52:24 -0000
@@ -839,6 +839,7 @@ function_entry basic_functions[] = {
PHP_FE(next, first_arg_force_ref)
PHP_FE(reset, first_arg_force_ref)
PHP_FE(current, first_arg_force_ref)
+ PHP_FE(array_has_more, first_arg_force_ref)
PHP_FE(key, first_arg_force_ref)
PHP_FE(min,
NULL)
PHP_FE(max,
NULL)
Index: ext/standard/php_array.h
===================================================================
RCS file: /repository/php-src/ext/standard/php_array.h,v
retrieving revision 1.43
diff -u -p -r1.43 php_array.h
--- ext/standard/php_array.h 10 Jun 2003 20:03:38 -0000 1.43
+++ ext/standard/php_array.h 4 Jul 2003 01:52:24 -0000
@@ -85,6 +85,7 @@ PHP_FUNCTION(array_map);
PHP_FUNCTION(array_key_exists);
PHP_FUNCTION(array_chunk);
PHP_FUNCTION(array_combine);
+PHP_FUNCTION(array_has_more);
HashTable* php_splice(HashTable *, int, int, zval ***, int, HashTable **);
PHPAPI int php_array_merge(HashTable *dest, HashTable *src, int recursive TSRMLS_DC);
Index: ext/standard/array.c
===================================================================
RCS file: /repository/php-src/ext/standard/array.c,v
retrieving revision 1.234
diff -u -p -r1.234 array.c
--- ext/standard/array.c 16 Jun 2003 17:35:16 -0000 1.234
+++ ext/standard/array.c 4 Jul 2003 01:52:25 -0000
@@ -3781,6 +3781,29 @@ PHP_FUNCTION(array_combine)
}
/* }}} */
+/* {{{ proto boolean array_has_more(array array_arg)
+ * */
+PHP_FUNCTION(array_has_more)
+{
+ pval **array;
+ HashTable *target_hash;
+
+ if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &array) == FAILURE) {
+ WRONG_PARAM_COUNT;
+ }
+ target_hash = HASH_OF(*array);
+ if (!target_hash) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Passed variable is not an
array or object");
+ RETURN_FALSE;
+ }
+ if (zend_hash_has_more_elements(target_hash) == SUCCESS) {
+ RETURN_TRUE;
+ } else {
+ RETURN_FALSE;
+ }
+}
+/* }}} */
+
/*
* Local variables:
* tab-width: 4
Index: Zend/zend_hash.c
===================================================================
RCS file: /repository/ZendEngine2/zend_hash.c,v
retrieving revision 1.102
diff -u -p -r1.102 zend_hash.c
--- Zend/zend_hash.c 14 Jun 2003 11:32:30 -0000 1.102
+++ Zend/zend_hash.c 4 Jul 2003 01:52:26 -0000
@@ -1005,6 +1005,20 @@ ZEND_API void zend_hash_internal_pointer
}
+ZEND_API int zend_hash_has_more_elements_ex(HashTable *ht, HashPosition *pos)
+{
+ HashPosition *current = pos ? pos : &ht->pInternalPointer;
+
+ IS_CONSISTENT(ht);
+
+ if (*current && (*current)->pListNext) {
+ return SUCCESS;
+ } else {
+ return FAILURE;
+ }
+}
+
+
ZEND_API int zend_hash_move_forward_ex(HashTable *ht, HashPosition *pos)
{
HashPosition *current = pos ? pos : &ht->pInternalPointer;
Index: Zend/zend_hash.h
===================================================================
RCS file: /repository/ZendEngine2/zend_hash.h,v
retrieving revision 1.67
diff -u -p -r1.67 zend_hash.h
--- Zend/zend_hash.h 10 Jun 2003 20:03:25 -0000 1.67
+++ Zend/zend_hash.h 4 Jul 2003 01:52:26 -0000
@@ -164,6 +164,7 @@ ZEND_API int zend_hash_index_exists(Hash
ZEND_API ulong zend_hash_next_free_element(HashTable *ht);
/* traversing */
+ZEND_API int zend_hash_has_more_elements_ex(HashTable *ht, HashPosition *pos);
ZEND_API int zend_hash_move_forward_ex(HashTable *ht, HashPosition *pos);
ZEND_API int zend_hash_move_backwards_ex(HashTable *ht, HashPosition *pos);
ZEND_API int zend_hash_get_current_key_ex(HashTable *ht, char **str_index, uint
*str_length, ulong *num_index, zend_bool duplicate, HashPosition *pos);
@@ -172,6 +173,8 @@ ZEND_API int zend_hash_get_current_data_
ZEND_API void zend_hash_internal_pointer_reset_ex(HashTable *ht, HashPosition *pos);
ZEND_API void zend_hash_internal_pointer_end_ex(HashTable *ht, HashPosition *pos);
+#define zend_hash_has_more_elements(ht) \
+ zend_hash_has_more_elements_ex(ht, NULL)
#define zend_hash_move_forward(ht) \
zend_hash_move_forward_ex(ht, NULL)
#define zend_hash_move_backwards(ht) \
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php