From: Ilia Alshanetsky Date: Sun, 3 Dec 2006 21:27:51 +0000 (+0000) Subject: MFB: Added "default" option that allows a default value to be set for an X-Git-Tag: RELEASE_1_0_0RC1~842 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a1721fa5d988c85ff35f9e3e24b5700522a2be10;p=php MFB: Added "default" option that allows a default value to be set for an invalid or missing value. --- diff --git a/ext/filter/filter.c b/ext/filter/filter.c index 0fc5cc01a6..44780f15ce 100644 --- a/ext/filter/filter.c +++ b/ext/filter/filter.c @@ -319,6 +319,19 @@ static void php_zval_filter(zval **value, long filter, long flags, zval *options convert_to_string(*value); filter_func.function(*value, flags, options, charset TSRMLS_CC); + + if ( + options && + ((flags & FILTER_NULL_ON_FAILURE && Z_TYPE_PP(value) == IS_NULL) || + (!(flags & FILTER_NULL_ON_FAILURE) && Z_TYPE_PP(value) == IS_BOOL && Z_LVAL_PP(value) == 0)) && + zend_hash_exists(HASH_OF(options), "default", sizeof("default")) + ) { + zval **tmp; + if (zend_hash_find(HASH_OF(options), "default", sizeof("default"), (void **)&tmp) == SUCCESS) { + **value = **tmp; + zval_copy_ctor(*value); + } + } } /* }}} */ @@ -678,13 +691,20 @@ PHP_FUNCTION(filter_input) if (!input || !HASH_OF(input) || zend_hash_find(HASH_OF(input), var, var_len + 1, (void **)&tmp) != SUCCESS) { long filter_flags = 0; - zval **option; + zval **option, **opt, **def; if (filter_args) { if (Z_TYPE_PP(filter_args) == IS_LONG) { filter_flags = Z_LVAL_PP(filter_args); } else if (Z_TYPE_PP(filter_args) == IS_ARRAY && zend_hash_find(HASH_OF(*filter_args), "flags", sizeof("flags"), (void **)&option) == SUCCESS) { convert_to_long(*option); filter_flags = Z_LVAL_PP(option); + } else if (Z_TYPE_PP(filter_args) == IS_ARRAY && + zend_hash_find(HASH_OF(*filter_args), "options", sizeof("options"), (void **)&opt) == SUCCESS && + zend_hash_find(HASH_OF(*opt), "default", sizeof("default"), (void **)&def) == SUCCESS + ) { + *return_value = **def; + zval_copy_ctor(return_value); + return; } } if (filter_flags & FILTER_NULL_ON_FAILURE) {