From: Antony Dovgal Date: Tue, 19 Sep 2006 09:33:02 +0000 (+0000) Subject: support objects in array_walk*() X-Git-Tag: RELEASE_1_0_0RC1~1630 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=591477b1435eb7dc6e25fd735de712e264e3d658;p=php support objects in array_walk*() add new tests, fix old ones --- diff --git a/ext/standard/array.c b/ext/standard/array.c index aadb5aa241..54623a9e95 100644 --- a/ext/standard/array.c +++ b/ext/standard/array.c @@ -1115,18 +1115,27 @@ PHP_FUNCTION(array_walk) *userdata = NULL; zend_fcall_info orig_array_walk_fci; zend_fcall_info_cache orig_array_walk_fci_cache; + HashTable *target_hash; orig_array_walk_fci = BG(array_walk_fci); orig_array_walk_fci_cache = BG(array_walk_fci_cache); - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "af|z", &array, + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zf|z", &array, &BG(array_walk_fci), &BG(array_walk_fci_cache), &userdata) == FAILURE) { BG(array_walk_fci) = orig_array_walk_fci; BG(array_walk_fci_cache) = orig_array_walk_fci_cache; return; } - php_array_walk(HASH_OF(array), userdata ? &userdata : NULL, 0 TSRMLS_CC); + target_hash = HASH_OF(array); + if (!target_hash) { + BG(array_walk_fci) = orig_array_walk_fci; + BG(array_walk_fci_cache) = orig_array_walk_fci_cache; + php_error_docref(NULL TSRMLS_CC, E_WARNING, "The argument should be an array"); + RETURN_FALSE; + } + + php_array_walk(target_hash, userdata ? &userdata : NULL, 0 TSRMLS_CC); BG(array_walk_fci) = orig_array_walk_fci; BG(array_walk_fci_cache) = orig_array_walk_fci_cache; RETURN_TRUE; @@ -1141,17 +1150,26 @@ PHP_FUNCTION(array_walk_recursive) *userdata = NULL; zend_fcall_info orig_array_walk_fci; zend_fcall_info_cache orig_array_walk_fci_cache; + HashTable *target_hash; orig_array_walk_fci = BG(array_walk_fci); orig_array_walk_fci_cache = BG(array_walk_fci_cache); - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "af|z", &array, + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zf|z", &array, &BG(array_walk_fci), &BG(array_walk_fci_cache), &userdata) == FAILURE) { BG(array_walk_fci) = orig_array_walk_fci; BG(array_walk_fci_cache) = orig_array_walk_fci_cache; return; } + target_hash = HASH_OF(array); + if (!target_hash) { + BG(array_walk_fci) = orig_array_walk_fci; + BG(array_walk_fci_cache) = orig_array_walk_fci_cache; + php_error_docref(NULL TSRMLS_CC, E_WARNING, "The argument should be an array"); + RETURN_FALSE; + } + php_array_walk(HASH_OF(array), userdata ? &userdata : NULL, 1 TSRMLS_CC); BG(array_walk_fci) = orig_array_walk_fci; BG(array_walk_fci_cache) = orig_array_walk_fci_cache; diff --git a/ext/standard/tests/array/array_walk.phpt b/ext/standard/tests/array/array_walk.phpt index 0cd4a650f3..3c9b1b8f93 100644 --- a/ext/standard/tests/array/array_walk.phpt +++ b/ext/standard/tests/array/array_walk.phpt @@ -34,7 +34,7 @@ echo "Done\n"; Warning: array_walk() expects at least 2 parameters, 0 given in %s on line %d NULL -Warning: array_walk() expects parameter 1 to be array, integer given in %s on line %d +Warning: array_walk() expects parameter 2 to be valid callback, integer given in %s on line %d NULL Warning: array_walk() expects parameter 2 to be valid callback, string given in %s on line %d @@ -52,7 +52,7 @@ Done Warning: array_walk() expects at least 2 parameters, 0 given in %s on line %d NULL -Warning: array_walk() expects parameter 1 to be array, integer given in %s on line %d +Warning: array_walk() expects parameter 2 to be valid callback, integer given in %s on line %d NULL Warning: array_walk() expects parameter 2 to be valid callback, Unicode string given in %s on line %d diff --git a/ext/standard/tests/array/array_walk_objects.phpt b/ext/standard/tests/array/array_walk_objects.phpt new file mode 100644 index 0000000000..40d50b19cc Binary files /dev/null and b/ext/standard/tests/array/array_walk_objects.phpt differ diff --git a/ext/standard/tests/array/array_walk_rec_objects.phpt b/ext/standard/tests/array/array_walk_rec_objects.phpt new file mode 100644 index 0000000000..380d83ee03 Binary files /dev/null and b/ext/standard/tests/array/array_walk_rec_objects.phpt differ diff --git a/ext/standard/tests/array/array_walk_recursive1.phpt b/ext/standard/tests/array/array_walk_recursive1.phpt index 5863a85ebd..ba275346e7 100644 --- a/ext/standard/tests/array/array_walk_recursive1.phpt +++ b/ext/standard/tests/array/array_walk_recursive1.phpt @@ -34,7 +34,7 @@ echo "Done\n"; Warning: array_walk_recursive() expects at least 2 parameters, 0 given in %s on line %d NULL -Warning: array_walk_recursive() expects parameter 1 to be array, integer given in %s on line %d +Warning: array_walk_recursive() expects parameter 2 to be valid callback, integer given in %s on line %d NULL Warning: array_walk_recursive() expects parameter 2 to be valid callback, string given in %s on line %d @@ -58,7 +58,7 @@ Done Warning: array_walk_recursive() expects at least 2 parameters, 0 given in %s on line %d NULL -Warning: array_walk_recursive() expects parameter 1 to be array, integer given in %s on line %d +Warning: array_walk_recursive() expects parameter 2 to be valid callback, integer given in %s on line %d NULL Warning: array_walk_recursive() expects parameter 2 to be valid callback, Unicode string given in %s on line %d