Skip to content

Commit fe193ae

Browse files
committed
IRequest, IResponse, Url: parameters $default are deprecated
1 parent d056a71 commit fe193ae

File tree

6 files changed

+32
-35
lines changed

6 files changed

+32
-35
lines changed

src/Http/IRequest.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,17 @@ function getUrl();
3737
* Returns variable provided to the script via URL query ($_GET).
3838
* If no key is passed, returns the entire array.
3939
* @param string key
40-
* @param mixed default value
4140
* @return mixed
4241
*/
43-
function getQuery($key = NULL, $default = NULL);
42+
function getQuery($key = NULL);
4443

4544
/**
4645
* Returns variable provided to the script via POST method ($_POST).
4746
* If no key is passed, returns the entire array.
4847
* @param string key
49-
* @param mixed default value
5048
* @return mixed
5149
*/
52-
function getPost($key = NULL, $default = NULL);
50+
function getPost($key = NULL);
5351

5452
/**
5553
* Returns uploaded file.
@@ -67,10 +65,9 @@ function getFiles();
6765
/**
6866
* Returns variable provided to the script via HTTP cookies.
6967
* @param string key
70-
* @param mixed default value
7168
* @return mixed
7269
*/
73-
function getCookie($key, $default = NULL);
70+
function getCookie($key);
7471

7572
/**
7673
* Returns variables provided to the script via HTTP cookies.
@@ -97,10 +94,9 @@ function isMethod($method);
9794
* Return the value of the HTTP header. Pass the header name as the
9895
* plain, HTTP-specified header name (e.g. 'Accept-Encoding').
9996
* @param string
100-
* @param string|NULL
10197
* @return string|NULL
10298
*/
103-
function getHeader($header, $default = NULL);
99+
function getHeader($header);
104100

105101
/**
106102
* Returns all HTTP headers.

src/Http/IResponse.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,9 @@ function isSent();
145145
/**
146146
* Returns value of an HTTP header.
147147
* @param string
148-
* @param string|NULL
149148
* @return string|NULL
150149
*/
151-
function getHeader($header, $default = NULL);
150+
function getHeader($header);
152151

153152
/**
154153
* Returns a list of headers to sent.

src/Http/Request.php

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -97,37 +97,33 @@ public function getUrl()
9797
* Returns variable provided to the script via URL query ($_GET).
9898
* If no key is passed, returns the entire array.
9999
* @param string key
100-
* @param mixed default value
101100
* @return mixed
102101
*/
103-
public function getQuery($key = NULL, $default = NULL)
102+
public function getQuery($key = NULL)
104103
{
105104
if (func_num_args() === 0) {
106105
return $this->url->getQueryParameters();
107-
} else {
108-
return $this->url->getQueryParameter($key, $default);
106+
} elseif (func_num_args() > 1) {
107+
trigger_error(__METHOD__ . '() parameter $default is deprecated, use operator ??', E_USER_DEPRECATED);
109108
}
109+
return $this->url->getQueryParameter($key);
110110
}
111111

112112

113113
/**
114114
* Returns variable provided to the script via POST method ($_POST).
115115
* If no key is passed, returns the entire array.
116116
* @param string key
117-
* @param mixed default value
118117
* @return mixed
119118
*/
120-
public function getPost($key = NULL, $default = NULL)
119+
public function getPost($key = NULL)
121120
{
122121
if (func_num_args() === 0) {
123122
return $this->post;
124-
125-
} elseif (isset($this->post[$key])) {
126-
return $this->post[$key];
127-
128-
} else {
129-
return $default;
123+
} elseif (func_num_args() > 1) {
124+
trigger_error(__METHOD__ . '() parameter $default is deprecated, use operator ??', E_USER_DEPRECATED);
130125
}
126+
return $this->post[$key] ?? NULL;
131127
}
132128

133129

@@ -155,12 +151,14 @@ public function getFiles()
155151
/**
156152
* Returns variable provided to the script via HTTP cookies.
157153
* @param string key
158-
* @param mixed default value
159154
* @return mixed
160155
*/
161-
public function getCookie($key, $default = NULL)
156+
public function getCookie($key)
162157
{
163-
return $this->cookies[$key] ?? $default;
158+
if (func_num_args() > 1) {
159+
trigger_error(__METHOD__ . '() parameter $default is deprecated, use operator ??', E_USER_DEPRECATED);
160+
}
161+
return $this->cookies[$key] ?? NULL;
164162
}
165163

166164

@@ -202,13 +200,15 @@ public function isMethod($method)
202200
* Return the value of the HTTP header. Pass the header name as the
203201
* plain, HTTP-specified header name (e.g. 'Accept-Encoding').
204202
* @param string
205-
* @param string|NULL
206203
* @return string|NULL
207204
*/
208-
public function getHeader($header, $default = NULL)
205+
public function getHeader($header)
209206
{
207+
if (func_num_args() > 1) {
208+
trigger_error(__METHOD__ . '() parameter $default is deprecated, use operator ??', E_USER_DEPRECATED);
209+
}
210210
$header = strtolower($header);
211-
return $this->headers[$header] ?? $default;
211+
return $this->headers[$header] ?? NULL;
212212
}
213213

214214

src/Http/Response.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,19 +200,20 @@ public function isSent()
200200
/**
201201
* Returns value of an HTTP header.
202202
* @param string
203-
* @param string|NULL
204203
* @return string|NULL
205204
*/
206-
public function getHeader($header, $default = NULL)
205+
public function getHeader($header)
207206
{
207+
if (func_num_args() > 1) {
208+
trigger_error(__METHOD__ . '() parameter $default is deprecated, use operator ??', E_USER_DEPRECATED);
209+
}
208210
$header .= ':';
209211
$len = strlen($header);
210212
foreach (headers_list() as $item) {
211213
if (strncasecmp($item, $header, $len) === 0) {
212214
return ltrim(substr($item, $len));
213215
}
214216
}
215-
return $default;
216217
}
217218

218219

src/Http/Url.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -299,12 +299,14 @@ public function getQueryParameters()
299299

300300
/**
301301
* @param string
302-
* @param mixed
303302
* @return mixed
304303
*/
305-
public function getQueryParameter($name, $default = NULL)
304+
public function getQueryParameter($name)
306305
{
307-
return $this->query[$name] ?? $default;
306+
if (func_num_args() > 1) {
307+
trigger_error(__METHOD__ . '() parameter $default is deprecated, use operator ??', E_USER_DEPRECATED);
308+
}
309+
return $this->query[$name] ?? NULL;
308310
}
309311

310312

tests/Http/Url.query.phpt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ Assert::same(['arg3' => 'value3'], $url->getQueryParameters());
5050
$url->setQuery(['arg' => 'value']);
5151
Assert::same('value', $url->getQueryParameter('arg'));
5252
Assert::same(NULL, $url->getQueryParameter('invalid'));
53-
Assert::same(123, $url->getQueryParameter('invalid', 123));
5453

5554
$url->setQueryParameter('arg2', 'abc');
5655
Assert::same('abc', $url->getQueryParameter('arg2'));

0 commit comments

Comments
 (0)