Skip to content

Commit

Permalink
fix: PHP 8.1 Passing null to parameter of type string is deprecated
Browse files Browse the repository at this point in the history
  • Loading branch information
twinh committed Nov 30, 2023
1 parent 5d18ebf commit f1376e1
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion lib/Http.php
Original file line number Diff line number Diff line change
Expand Up @@ -921,7 +921,7 @@ protected function prepareCurlOptions()
if ($this->cookies) {
$cookies = [];
foreach ($this->cookies as $key => $value) {
$cookies[] = $key . '=' . rawurlencode($value);
$cookies[] = $key . '=' . rawurlencode($value ?? '');
}
$opts[\CURLOPT_COOKIE] = implode('; ', $cookies);
}
Expand Down
3 changes: 2 additions & 1 deletion lib/IsContains.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ public function __invoke($input, $search = null, $regex = false)
*/
protected function doValidate($input)
{
if (!$this->isString($input)) {
$input = $this->toString($input);
if (null === $input) {
$this->addError('notString');
return false;
}
Expand Down
3 changes: 2 additions & 1 deletion lib/IsDir.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ class IsDir extends BaseValidator
*/
protected function doValidate($input)
{
if (!$this->isString($input)) {
$input = $this->toString($input);
if (null === $input) {
$this->addError('notString');
return false;
}
Expand Down
3 changes: 2 additions & 1 deletion lib/IsExists.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ class IsExists extends BaseValidator
*/
protected function doValidate($input)
{
if (!$this->isString($input)) {
$input = $this->toString($input);
if (null === $input) {
$this->addError('notString');
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Req.php
Original file line number Diff line number Diff line change
Expand Up @@ -842,7 +842,7 @@ public function getIterator(): \Traversable
*/
public function accept($mine)
{
return 0 === strpos($this->getServer('HTTP_ACCEPT'), $mine);
return 0 === strpos($this->getServer('HTTP_ACCEPT', ''), $mine);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions lib/Res.php
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ public function redirect($url = null, $statusCode = 302, $options = [])
$this->setOption($options);

// The variables for custom redirect view
$escapedUrl = htmlspecialchars($url, \ENT_QUOTES, 'UTF-8');
$escapedUrl = $url ? htmlspecialchars($url, \ENT_QUOTES, 'UTF-8') : $url;
$wait = (int) $this->redirectWait;

// Location header does not support delay
Expand Down Expand Up @@ -716,7 +716,7 @@ public function download($file = null, array $downloadOptions = [])
$name = rawurlencode($name);

// For IE
$userAgent = $this->request->getServer('HTTP_USER_AGENT');
$userAgent = $this->request->getServer('HTTP_USER_AGENT', '');
if (preg_match('/MSIE ([\w.]+)/', $userAgent)) {
$filename = '=' . $name;
} else {
Expand Down
2 changes: 1 addition & 1 deletion lib/WeChatApp.php
Original file line number Diff line number Diff line change
Expand Up @@ -1029,7 +1029,7 @@ protected function arrayToXml(array $array, SimpleXMLElement $xml = null)
} else {
$child = $xml->addChild($key);
$node = dom_import_simplexml($child);
$node->appendChild($node->ownerDocument->createCDATASection($value));
$node->appendChild($node->ownerDocument->createCDATASection($value ?? ''));
}
}
}
Expand Down

0 comments on commit f1376e1

Please sign in to comment.