diff --git a/README.md b/README.md index 5e2e1ae..bff3d01 100644 --- a/README.md +++ b/README.md @@ -2,4 +2,4 @@ Like wp_parse_args but supports recursivity. -Additionally converts the returned type based on the $args and $defaults +By default converts the returned type based on the $args and $defaults diff --git a/composer.json b/composer.json index d117d3a..ba241dc 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "23r9i0/wp_parse_args_recursive", - "description": "Like wp_parse_args but supports recursivity. Additionally converts the returned type based on the $args and $defaults", + "description": "Like wp_parse_args but supports recursivity. By default converts the returned type based on the $args and $defaults", "type": "library", "homepage": "https://github.com/23r9i0/wp_parse_args_recursive", "license": "GPL-2.0+", diff --git a/src/wp_parse_args_recursive.php b/src/wp_parse_args_recursive.php index 43ac386..bf2d1e7 100644 --- a/src/wp_parse_args_recursive.php +++ b/src/wp_parse_args_recursive.php @@ -1,25 +1,22 @@ - * * @license https://www.gnu.org/licenses/gpl-2.0.html GPL2 or later - * * @version 1.0 * * @param array|object $args Values to merge with $defaults * @param array|object $defaults Array or Object that serves as the defaults. + * @param boolean $preserve_type Optional. Convert output array into object if $args or $defaults if it is. Default true * @param boolean $preserve_integer_keys Optional. If given, integer keys will be preserved and merged instead of appended. Default false. * * @return array|object $output Merged user defined values with defaults. */ if ( ! function_exists( 'wp_parse_args_recursive' ) ) { - function wp_parse_args_recursive( $args, $defaults, $preserve_integer_keys = false ) { + function wp_parse_args_recursive( $args, $defaults, $preserve_type = true, $preserve_integer_keys = false ) { $output = array(); foreach ( array( $defaults, $args ) as $list ) { @@ -38,6 +35,6 @@ function wp_parse_args_recursive( $args, $defaults, $preserve_integer_keys = fal } } - return ( is_object( $args ) || is_object( $defaults ) ) ? (object) $output : $output; + return ( $preserve_type && ( is_object( $args ) || is_object( $defaults ) ) ) ? (object) $output : $output; } }