]> granicus.if.org Git - php/commitdiff
MFB: Added "default" option that allows a default value to be set for an
authorIlia Alshanetsky <iliaa@php.net>
Sun, 3 Dec 2006 21:27:51 +0000 (21:27 +0000)
committerIlia Alshanetsky <iliaa@php.net>
Sun, 3 Dec 2006 21:27:51 +0000 (21:27 +0000)
invalid or missing value.

ext/filter/filter.c

index 0fc5cc01a64f78acb9a23726748472f6c800ef46..44780f15ce858b0a96231e49e7f0a937da3d70e7 100644 (file)
@@ -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) {