From 8619dabb21e9ee53ea052c7072955e114075c983 Mon Sep 17 00:00:00 2001
From: ken678 <530765310@qq.com>
Date: Mon, 24 Jul 2023 16:26:20 +0800
Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0php8.1?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
library/think/Collection.php | 9 ++++++++-
library/think/Config.php | 7 +++++--
library/think/Container.php | 11 ++++++++---
library/think/Model.php | 7 +++++--
library/think/Paginator.php | 16 +++++++++++-----
library/think/Request.php | 2 +-
library/think/model/concern/Conversion.php | 2 +-
7 files changed, 39 insertions(+), 15 deletions(-)
diff --git a/library/think/Collection.php b/library/think/Collection.php
index cdb7e19..aeadef2 100644
--- a/library/think/Collection.php
+++ b/library/think/Collection.php
@@ -16,6 +16,7 @@
use Countable;
use IteratorAggregate;
use JsonSerializable;
+use Traversable;
class Collection implements ArrayAccess, Countable, IteratorAggregate, JsonSerializable
{
@@ -470,16 +471,19 @@ public function slice($offset, $length = null, $preserveKeys = false)
}
// ArrayAccess
+ #[\ReturnTypeWillChange]
public function offsetExists($offset): bool
{
return array_key_exists($offset, $this->items);
}
+ #[\ReturnTypeWillChange]
public function offsetGet($offset)
{
return $this->items[$offset];
}
+ #[\ReturnTypeWillChange]
public function offsetSet($offset, $value)
{
if (is_null($offset)) {
@@ -489,6 +493,7 @@ public function offsetSet($offset, $value)
}
}
+ #[\ReturnTypeWillChange]
public function offsetUnset($offset)
{
unset($this->items[$offset]);
@@ -501,12 +506,14 @@ public function count(): int
}
//IteratorAggregate
- public function getIterator()
+ #[\ReturnTypeWillChange]
+ public function getIterator(): Traversable
{
return new ArrayIterator($this->items);
}
//JsonSerializable
+ #[\ReturnTypeWillChange]
public function jsonSerialize()
{
return $this->toArray();
diff --git a/library/think/Config.php b/library/think/Config.php
index bec6222..ccb71c3 100644
--- a/library/think/Config.php
+++ b/library/think/Config.php
@@ -375,22 +375,25 @@ public function __isset($name)
return $this->has($name);
}
- // ArrayAccess
+ #[\ReturnTypeWillChange]
public function offsetSet($name, $value)
{
$this->set($name, $value);
}
- public function offsetExists($name)
+ #[\ReturnTypeWillChange]
+ public function offsetExists($name): bool
{
return $this->has($name);
}
+ #[\ReturnTypeWillChange]
public function offsetUnset($name)
{
$this->remove($name);
}
+ #[\ReturnTypeWillChange]
public function offsetGet($name)
{
return $this->get($name);
diff --git a/library/think/Container.php b/library/think/Container.php
index bb97423..3d4d10a 100644
--- a/library/think/Container.php
+++ b/library/think/Container.php
@@ -23,6 +23,7 @@
use ReflectionMethod;
use think\exception\ClassNotFoundException;
use think\exception\FuncNotFoundException;
+use Traversable;
/**
* @package think
@@ -585,34 +586,38 @@ public function __unset($name)
$this->delete($name);
}
- public function offsetExists($key)
+ #[\ReturnTypeWillChange]
+ public function offsetExists($key): bool
{
return $this->__isset($key);
}
+ #[\ReturnTypeWillChange]
public function offsetGet($key)
{
return $this->__get($key);
}
+ #[\ReturnTypeWillChange]
public function offsetSet($key, $value)
{
$this->__set($key, $value);
}
+ #[\ReturnTypeWillChange]
public function offsetUnset($key)
{
$this->__unset($key);
}
//Countable
- public function count()
+ public function count(): int
{
return count($this->instances);
}
//IteratorAggregate
- public function getIterator()
+ public function getIterator(): Traversable
{
return new ArrayIterator($this->instances);
}
diff --git a/library/think/Model.php b/library/think/Model.php
index 50f2ca1..5165dca 100644
--- a/library/think/Model.php
+++ b/library/think/Model.php
@@ -1073,22 +1073,25 @@ public function __unset($name)
unset($this->data[$name], $this->relation[$name]);
}
- // ArrayAccess
+ #[\ReturnTypeWillChange]
public function offsetSet($name, $value)
{
$this->setAttr($name, $value);
}
- public function offsetExists($name)
+ #[\ReturnTypeWillChange]
+ public function offsetExists($name): bool
{
return $this->__isset($name);
}
+ #[\ReturnTypeWillChange]
public function offsetUnset($name)
{
$this->__unset($name);
}
+ #[\ReturnTypeWillChange]
public function offsetGet($name)
{
return $this->getAttr($name);
diff --git a/library/think/Paginator.php b/library/think/Paginator.php
index bbe63e2..97f7ea9 100644
--- a/library/think/Paginator.php
+++ b/library/think/Paginator.php
@@ -150,7 +150,7 @@ protected function url($page)
$url = $path;
if (!empty($parameters)) {
- $url .= '?' . http_build_query($parameters, null, '&');
+ $url .= '?' . http_build_query($parameters, '', '&');
}
return $url . $this->buildFragment();
@@ -341,7 +341,8 @@ public function each(callable $callback)
* @return Traversable An instance of an object implementing Iterator or
* Traversable
*/
- public function getIterator()
+ #[\ReturnTypeWillChange]
+ public function getIterator(): Traversable
{
return new ArrayIterator($this->items->all());
}
@@ -352,7 +353,8 @@ public function getIterator()
* @param mixed $offset
* @return bool
*/
- public function offsetExists($offset)
+ #[\ReturnTypeWillChange]
+ public function offsetExists($offset): bool
{
return $this->items->offsetExists($offset);
}
@@ -363,6 +365,7 @@ public function offsetExists($offset)
* @param mixed $offset
* @return mixed
*/
+ #[\ReturnTypeWillChange]
public function offsetGet($offset)
{
return $this->items->offsetGet($offset);
@@ -374,6 +377,7 @@ public function offsetGet($offset)
* @param mixed $offset
* @param mixed $value
*/
+ #[\ReturnTypeWillChange]
public function offsetSet($offset, $value)
{
$this->items->offsetSet($offset, $value);
@@ -386,6 +390,7 @@ public function offsetSet($offset, $value)
* @return void
* @since 5.0.0
*/
+ #[\ReturnTypeWillChange]
public function offsetUnset($offset)
{
$this->items->offsetUnset($offset);
@@ -394,7 +399,7 @@ public function offsetUnset($offset)
/**
* Count elements of an object
*/
- public function count()
+ public function count(): int
{
return $this->items->count();
}
@@ -404,7 +409,7 @@ public function __toString()
return (string) $this->render();
}
- public function toArray()
+ public function toArray(): array
{
try {
$total = $this->total();
@@ -424,6 +429,7 @@ public function toArray()
/**
* Specify data which should be serialized to JSON
*/
+ #[\ReturnTypeWillChange]
public function jsonSerialize()
{
return $this->toArray();
diff --git a/library/think/Request.php b/library/think/Request.php
index 6b6dd4b..3cf48bc 100644
--- a/library/think/Request.php
+++ b/library/think/Request.php
@@ -1655,7 +1655,7 @@ public function isJson()
public function isAjax($ajax = false)
{
$value = $this->server('HTTP_X_REQUESTED_WITH');
- $result = 'xmlhttprequest' == strtolower($value) ? true : false;
+ $result = $value && 'xmlhttprequest' == strtolower($value) ? true : false;
if (true === $ajax) {
return $result;
diff --git a/library/think/model/concern/Conversion.php b/library/think/model/concern/Conversion.php
index de4db93..057a3b6 100644
--- a/library/think/model/concern/Conversion.php
+++ b/library/think/model/concern/Conversion.php
@@ -244,7 +244,7 @@ public function __toString()
return $this->toJson();
}
- // JsonSerializable
+ #[\ReturnTypeWillChange]
public function jsonSerialize()
{
return $this->toArray();