iliaa Thu, 28 Apr 2011 12:32:47 +0000
Revision: http://svn.php.net/viewvc?view=revision&revision=310622
Log:
#doc
Added 3rd parameter to filter_var_array() and filter_input_array()
functions that allows disabling addition of empty elements
Changed paths:
U php/php-src/branches/PHP_5_3/NEWS
U php/php-src/branches/PHP_5_3/ext/filter/filter.c
A php/php-src/branches/PHP_5_3/ext/filter/tests/054.phpt
U php/php-src/trunk/ext/filter/filter.c
A php/php-src/trunk/ext/filter/tests/054.phpt
Modified: php/php-src/branches/PHP_5_3/NEWS
===================================================================
--- php/php-src/branches/PHP_5_3/NEWS 2011-04-28 11:13:55 UTC (rev 310621)
+++ php/php-src/branches/PHP_5_3/NEWS 2011-04-28 12:32:47 UTC (rev 310622)
@@ -42,6 +42,8 @@
. Fixed bug #54121 (error message format string typo). (Ilia)
- Filter extension:
+ . Added 3rd parameter to filter_var_array() and filter_input_array()
+ functions that allows disabling addition of empty elements. (Ilia)
. Fixed bug #53037 (FILTER_FLAG_EMPTY_STRING_NULL is not implemented). (Ilia)
- intl extension:
Modified: php/php-src/branches/PHP_5_3/ext/filter/filter.c
===================================================================
--- php/php-src/branches/PHP_5_3/ext/filter/filter.c 2011-04-28 11:13:55 UTC
(rev 310621)
+++ php/php-src/branches/PHP_5_3/ext/filter/filter.c 2011-04-28 12:32:47 UTC
(rev 310622)
@@ -96,11 +96,13 @@
ZEND_BEGIN_ARG_INFO_EX(arginfo_filter_input_array, 0, 0, 1)
ZEND_ARG_INFO(0, type)
ZEND_ARG_INFO(0, definition)
+ ZEND_ARG_INFO(0, add_empty)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_filter_var_array, 0, 0, 1)
ZEND_ARG_INFO(0, data)
ZEND_ARG_INFO(0, definition)
+ ZEND_ARG_INFO(0, add_empty)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO(arginfo_filter_list, 0)
@@ -689,7 +691,7 @@
}
/* }}} */
-static void php_filter_array_handler(zval *input, zval **op, zval
*return_value TSRMLS_DC) /* {{{ */
+static void php_filter_array_handler(zval *input, zval **op, zval
*return_value, zend_bool add_empty TSRMLS_DC) /* {{{ */
{
char *arg_key;
uint arg_key_len;
@@ -724,7 +726,9 @@
RETURN_FALSE;
}
if (zend_hash_find(Z_ARRVAL_P(input), arg_key,
arg_key_len, (void **)&tmp) != SUCCESS) {
- add_assoc_null_ex(return_value, arg_key,
arg_key_len);
+ if (add_empty) {
+ add_assoc_null_ex(return_value,
arg_key, arg_key_len);
+ }
} else {
zval *nval;
@@ -821,15 +825,16 @@
}
/* }}} */
-/* {{{ proto mixed filter_input_array(constant type, [, mixed options]])
+/* {{{ proto mixed filter_input_array(constant type, [, mixed options [, bool
add_empty]]])
* Returns an array with all arguments defined in 'definition'.
*/
PHP_FUNCTION(filter_input_array)
{
long fetch_from;
zval *array_input = NULL, **op = NULL;
+ zend_bool add_empty = 1;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|Z",
&fetch_from, &op) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|Zb",
&fetch_from, &op, &add_empty) == FAILURE) {
return;
}
@@ -865,18 +870,19 @@
}
}
- php_filter_array_handler(array_input, op, return_value TSRMLS_CC);
+ php_filter_array_handler(array_input, op, return_value, add_empty
TSRMLS_CC);
}
/* }}} */
-/* {{{ proto mixed filter_var_array(array data, [, mixed options]])
+/* {{{ proto mixed filter_var_array(array data, [, mixed options [, bool
add_empty]]])
* Returns an array with all arguments defined in 'definition'.
*/
PHP_FUNCTION(filter_var_array)
{
zval *array_input = NULL, **op = NULL;
+ zend_bool add_empty = 1;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a|Z",
&array_input, &op) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a|Zb",
&array_input, &op, &add_empty) == FAILURE) {
return;
}
@@ -887,7 +893,7 @@
RETURN_FALSE;
}
- php_filter_array_handler(array_input, op, return_value TSRMLS_CC);
+ php_filter_array_handler(array_input, op, return_value, add_empty
TSRMLS_CC);
}
/* }}} */
Added: php/php-src/branches/PHP_5_3/ext/filter/tests/054.phpt
===================================================================
--- php/php-src/branches/PHP_5_3/ext/filter/tests/054.phpt
(rev 0)
+++ php/php-src/branches/PHP_5_3/ext/filter/tests/054.phpt 2011-04-28
12:32:47 UTC (rev 310622)
@@ -0,0 +1,26 @@
+--TEST--
+filter_var_array() - using the add_empty option
+--SKIPIF--
+<?php if (!extension_loaded("filter")) die("skip"); ?>
+--FILE--
+<?php
+
+$data = array('foo' => 123);
+
+var_dump(
+ filter_var_array($data, array('foo' => array('filter' =>
FILTER_DEFAULT), 'bar' => array('filter' => FILTER_DEFAULT)), false),
+ filter_var_array($data, array('foo' => array('filter' =>
FILTER_DEFAULT), 'bar' => array('filter' => FILTER_DEFAULT)))
+);
+
+?>
+--EXPECT--
+array(1) {
+ ["foo"]=>
+ string(3) "123"
+}
+array(2) {
+ ["foo"]=>
+ string(3) "123"
+ ["bar"]=>
+ NULL
+}
Modified: php/php-src/trunk/ext/filter/filter.c
===================================================================
--- php/php-src/trunk/ext/filter/filter.c 2011-04-28 11:13:55 UTC (rev
310621)
+++ php/php-src/trunk/ext/filter/filter.c 2011-04-28 12:32:47 UTC (rev
310622)
@@ -96,11 +96,13 @@
ZEND_BEGIN_ARG_INFO_EX(arginfo_filter_input_array, 0, 0, 1)
ZEND_ARG_INFO(0, type)
ZEND_ARG_INFO(0, definition)
+ ZEND_ARG_INFO(0, add_empty)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_filter_var_array, 0, 0, 1)
ZEND_ARG_INFO(0, data)
ZEND_ARG_INFO(0, definition)
+ ZEND_ARG_INFO(0, add_empty)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO(arginfo_filter_list, 0)
@@ -676,7 +678,7 @@
}
/* }}} */
-static void php_filter_array_handler(zval *input, zval **op, zval
*return_value TSRMLS_DC) /* {{{ */
+static void php_filter_array_handler(zval *input, zval **op, zval
*return_value, zend_bool add_empty TSRMLS_DC) /* {{{ */
{
char *arg_key;
uint arg_key_len;
@@ -711,7 +713,9 @@
RETURN_FALSE;
}
if (zend_hash_find(Z_ARRVAL_P(input), arg_key,
arg_key_len, (void **)&tmp) != SUCCESS) {
- add_assoc_null_ex(return_value, arg_key,
arg_key_len);
+ if (add_empty) {
+ add_assoc_null_ex(return_value,
arg_key, arg_key_len);
+ }
} else {
zval *nval;
@@ -808,15 +812,16 @@
}
/* }}} */
-/* {{{ proto mixed filter_input_array(constant type, [, mixed options]])
+/* {{{ proto mixed filter_input_array(constant type, [, mixed options [, bool
add_empty]]])
* Returns an array with all arguments defined in 'definition'.
*/
PHP_FUNCTION(filter_input_array)
{
long fetch_from;
zval *array_input = NULL, **op = NULL;
+ zend_bool add_empty = 1;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|Z",
&fetch_from, &op) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|Zb",
&fetch_from, &op, &add_empty) == FAILURE) {
return;
}
@@ -852,18 +857,19 @@
}
}
- php_filter_array_handler(array_input, op, return_value TSRMLS_CC);
+ php_filter_array_handler(array_input, op, return_value, add_empty
TSRMLS_CC);
}
/* }}} */
-/* {{{ proto mixed filter_var_array(array data, [, mixed options]])
+/* {{{ proto mixed filter_var_array(array data, [, mixed options [, bool
add_empty]]])
* Returns an array with all arguments defined in 'definition'.
*/
PHP_FUNCTION(filter_var_array)
{
zval *array_input = NULL, **op = NULL;
+ zend_bool add_empty = 1;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a|Z",
&array_input, &op) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a|Zb",
&array_input, &op, &add_empty) == FAILURE) {
return;
}
@@ -874,7 +880,7 @@
RETURN_FALSE;
}
- php_filter_array_handler(array_input, op, return_value TSRMLS_CC);
+ php_filter_array_handler(array_input, op, return_value, add_empty
TSRMLS_CC);
}
/* }}} */
Added: php/php-src/trunk/ext/filter/tests/054.phpt
===================================================================
--- php/php-src/trunk/ext/filter/tests/054.phpt (rev 0)
+++ php/php-src/trunk/ext/filter/tests/054.phpt 2011-04-28 12:32:47 UTC (rev
310622)
@@ -0,0 +1,26 @@
+--TEST--
+filter_var_array() - using the add_empty option
+--SKIPIF--
+<?php if (!extension_loaded("filter")) die("skip"); ?>
+--FILE--
+<?php
+
+$data = array('foo' => 123);
+
+var_dump(
+ filter_var_array($data, array('foo' => array('filter' =>
FILTER_DEFAULT), 'bar' => array('filter' => FILTER_DEFAULT)), false),
+ filter_var_array($data, array('foo' => array('filter' =>
FILTER_DEFAULT), 'bar' => array('filter' => FILTER_DEFAULT)))
+);
+
+?>
+--EXPECT--
+array(1) {
+ ["foo"]=>
+ string(3) "123"
+}
+array(2) {
+ ["foo"]=>
+ string(3) "123"
+ ["bar"]=>
+ NULL
+}
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php