1212 /**
1313 * Get an item of `GET` data if set, otherwise return a default value.
1414 *
15+ * @template T
1516 * @param string $key GET key.
16- * @param string $def Default value.
17- * @return mixed Value sanitized by xwp_uclean.
17+ * @param null|T $def Default value.
18+ * @return T
1819 */
19- function xwp_fetch_get_var ( $ key , $ def = null ) {
20+ function xwp_fetch_get_var ( string $ key , mixed $ def = null ): mixed {
2021 return f \Request::fetch_get_var ( $ key , $ def );
2122 }
2223endif ;
@@ -25,11 +26,12 @@ function xwp_fetch_get_var( $key, $def = null ) {
2526 /**
2627 * Get an item of `POST` data if set, otherwise return a default value.
2728 *
28- * @param string $key POST key.
29- * @param string $def Default value.
30- * @return mixed Value sanitized by xwp_uclean.
29+ * @template T
30+ * @param string $key POST key.
31+ * @param null|T $def Default value.
32+ * @return T Value sanitized by xwp_uclean.
3133 */
32- function xwp_fetch_post_var ( $ key , $ def = null ) {
34+ function xwp_fetch_post_var ( string $ key , mixed $ def = null ): mixed {
3335 return f \Request::fetch_post_var ( $ key , $ def );
3436 }
3537endif ;
@@ -38,9 +40,10 @@ function xwp_fetch_post_var( $key, $def = null ) {
3840 /**
3941 * Get an item of `REQUEST`data if set, otherwise return a default value.
4042 *
41- * @param string $key REQUEST key.
42- * @param string $def Default value.
43- * @return mixed Value sanitized by xwp_uclean.
43+ * @template T
44+ * @param string $key REQUEST key.
45+ * @param null|T $def Default value.
46+ * @return T Value sanitized by xwp_uclean.
4447 */
4548 function xwp_fetch_req_var ( $ key , $ def = null ) {
4649 return f \Request::fetch_req_var ( $ key , $ def );
@@ -51,11 +54,12 @@ function xwp_fetch_req_var( $key, $def = null ) {
5154 /**
5255 * Get an item of `SERVER` data if set, otherwise return a default value.
5356 *
54- * @param string $key SERVER key.
55- * @param string $def Default value.
56- * @return mixed Value sanitized by xwp_uclean.
57+ * @template T
58+ * @param string $key SERVER key.
59+ * @param null|T $def Default value.
60+ * @return T Value sanitized by xwp_uclean.
5761 */
58- function xwp_fetch_server_var ( $ key , $ def = null ) {
62+ function xwp_fetch_server_var ( string $ key , mixed $ def = null ): mixed {
5963 return f \Request::fetch_server_var ( $ key , $ def );
6064 }
6165endif ;
@@ -64,11 +68,11 @@ function xwp_fetch_server_var( $key, $def = null ) {
6468 /**
6569 * Get an item of `COOKIE` data if set, otherwise return a default value.
6670 *
67- * @param string $key COOKIE key.
68- * @param string $def Default value.
69- * @return mixed Value sanitized by xwp_uclean.
71+ * @param string $key COOKIE key.
72+ * @param string $def Default value.
73+ * @return string Value sanitized by xwp_uclean.
7074 */
71- function xwp_fetch_cookie_var ( $ key , $ def = null ) {
75+ function xwp_fetch_cookie_var ( string $ key , string $ def = '' ): string {
7276 return f \Request::fetch_cookie_var ( $ key , $ def );
7377 }
7478endif ;
@@ -90,32 +94,38 @@ function xwp_fetch_files_var( $key, $def = null ) {
9094 /**
9195 * Get the unslashed and cleaned $_GET array.
9296 *
93- * @return array<string, mixed>
97+ * @template T of array
98+ * @param T $def Default value.
99+ * @return T
94100 */
95- function xwp_get_arr (): array {
96- return f \Request::fetch_get_arr ();
101+ function xwp_get_arr ( array $ def = array () ): array {
102+ return xwp_parse_args ( f \Request::fetch_get_arr (), $ def );
97103 }
98104endif ;
99105
100106if ( ! function_exists ( 'xwp_post_arr ' ) ) :
101107 /**
102108 * Get the unslashed and cleaned $_POST array.
103109 *
104- * @return array<string, mixed>
110+ * @template T of array
111+ * @param T $def Default value.
112+ * @return T
105113 */
106- function xwp_post_arr (): array {
107- return f \Request::fetch_post_arr ();
114+ function xwp_post_arr ( array $ def = array () ): array {
115+ return xwp_parse_args ( f \Request::fetch_post_arr (), $ def );
108116 }
109117endif ;
110118
111119if ( ! function_exists ( 'xwp_req_arr ' ) ) :
112120 /**
113121 * Get the unslashed and cleaned $_REQUEST array.
114122 *
115- * @return array<string, mixed>
123+ * @template T of array
124+ * @param T $def Default value.
125+ * @return T
116126 */
117- function xwp_req_arr (): array {
118- return f \Request::fetch_req_arr ();
127+ function xwp_req_arr ( array $ def = array () ): array {
128+ return xwp_parse_args ( f \Request::fetch_req_arr (), $ def );
119129 }
120130endif ;
121131
0 commit comments