diff options
| author | datibbaw <datibbaw@php.net> | 2013-09-26 11:10:24 +0800 |
|---|---|---|
| committer | Tjerk Meesters <datibbaw@php.net> | 2013-09-28 00:06:04 +0800 |
| commit | 0492145e58bda8fed9f64992a9b8d054d9c80758 (patch) | |
| tree | b67e505dd24cc5ebd8d2eb8d55de2094bd8fee5f /ext/standard/array.c | |
| parent | b8653d34579409131b8dc6d92e7ac30e28fa95a6 (diff) | |
| download | php-git-0492145e58bda8fed9f64992a9b8d054d9c80758.tar.gz | |
added bitmask variation
Diffstat (limited to 'ext/standard/array.c')
| -rw-r--r-- | ext/standard/array.c | 36 |
1 files changed, 21 insertions, 15 deletions
diff --git a/ext/standard/array.c b/ext/standard/array.c index 1f98ef16f2..13148ec6f0 100644 --- a/ext/standard/array.c +++ b/ext/standard/array.c @@ -127,6 +127,10 @@ PHP_MINIT_FUNCTION(array) /* {{{ */ REGISTER_LONG_CONSTANT("COUNT_NORMAL", COUNT_NORMAL, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("COUNT_RECURSIVE", COUNT_RECURSIVE, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("ARRAY_FILTER_USE_BOTH", ARRAY_FILTER_USE_BOTH, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("ARRAY_FILTER_USE_KEY", ARRAY_FILTER_USE_KEY, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("ARRAY_FILTER_USE_VALUE", ARRAY_FILTER_USE_VALUE, CONST_CS | CONST_PERSISTENT); + return SUCCESS; } /* }}} */ @@ -4198,7 +4202,7 @@ PHP_FUNCTION(array_filter) zval *retval = NULL; zval *key = NULL; zend_bool have_callback = 0; - zend_bool use_key = 0; + long use_type = ARRAY_FILTER_USE_VALUE; char *string_key; zend_fcall_info fci = empty_fcall_info; zend_fcall_info_cache fci_cache = empty_fcall_info_cache; @@ -4206,7 +4210,7 @@ PHP_FUNCTION(array_filter) ulong num_key; HashPosition pos; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a|fb", &array, &fci, &fci_cache, &use_key) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a|fl", &array, &fci, &fci_cache, &use_type) == FAILURE) { return; } @@ -4220,11 +4224,14 @@ PHP_FUNCTION(array_filter) fci.no_separation = 0; fci.retval_ptr_ptr = &retval; - if (use_key) { + if (use_type == ARRAY_FILTER_USE_BOTH) { fci.param_count = 2; args[1] = &key; } else { fci.param_count = 1; + if (use_type == ARRAY_FILTER_USE_KEY) { + args[0] = &key; + } } } @@ -4235,7 +4242,7 @@ PHP_FUNCTION(array_filter) int key_type = zend_hash_get_current_key_ex(Z_ARRVAL_P(array), &string_key, &string_key_len, &num_key, 0, &pos); if (have_callback) { - if (use_key) { + if (use_type != ARRAY_FILTER_USE_VALUE) { MAKE_STD_ZVAL(key); /* Set up the key */ switch (key_type) { @@ -4250,21 +4257,20 @@ PHP_FUNCTION(array_filter) } } - args[0] = operand; + if (use_type != ARRAY_FILTER_USE_KEY) { + args[0] = operand; + } fci.params = args; if (zend_call_function(&fci, &fci_cache TSRMLS_CC) == SUCCESS && retval) { - if (!zend_is_true(retval)) { - zval_ptr_dtor(&retval); - if (use_key) { - zval_ptr_dtor(&key); - } + int retval_true = zend_is_true(retval); + + zval_ptr_dtor(&retval); + if (use_type != ARRAY_FILTER_USE_VALUE) { + zval_ptr_dtor(&key); + } + if (!retval_true) { continue; - } else { - zval_ptr_dtor(&retval); - if (use_key) { - zval_ptr_dtor(&key); - } } } else { php_error_docref(NULL TSRMLS_CC, E_WARNING, "An error occurred while invoking the filter callback"); |
