diff options
| author | Ilia Alshanetsky <iliaa@php.net> | 2006-12-03 21:27:36 +0000 |
|---|---|---|
| committer | Ilia Alshanetsky <iliaa@php.net> | 2006-12-03 21:27:36 +0000 |
| commit | b6bdd449620ed4f92a0bb90c7e1a91a50a74248e (patch) | |
| tree | 290f94b4379cff3123fd0b1313f94236e0a17486 /ext/filter | |
| parent | 9666f1deae9115cc9bec64d2f0d3b6db19a79ac3 (diff) | |
| download | php-git-b6bdd449620ed4f92a0bb90c7e1a91a50a74248e.tar.gz | |
Added "default" option that allows a default value to be set for an invalid
or missing value.
Diffstat (limited to 'ext/filter')
| -rw-r--r-- | ext/filter/filter.c | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/ext/filter/filter.c b/ext/filter/filter.c index 246fb67f18..faa7b472ed 100644 --- a/ext/filter/filter.c +++ b/ext/filter/filter.c @@ -320,6 +320,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); + } + } } /* }}} */ @@ -670,13 +683,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) { |
