Skip to content

Commit

Permalink
更新php8.1
Browse files Browse the repository at this point in the history
  • Loading branch information
ken678 committed Jul 24, 2023
1 parent f09cd7f commit 8619dab
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 15 deletions.
9 changes: 8 additions & 1 deletion library/think/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Countable;
use IteratorAggregate;
use JsonSerializable;
use Traversable;

class Collection implements ArrayAccess, Countable, IteratorAggregate, JsonSerializable
{
Expand Down Expand Up @@ -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)) {
Expand All @@ -489,6 +493,7 @@ public function offsetSet($offset, $value)
}
}

#[\ReturnTypeWillChange]
public function offsetUnset($offset)
{
unset($this->items[$offset]);
Expand All @@ -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();
Expand Down
7 changes: 5 additions & 2 deletions library/think/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
11 changes: 8 additions & 3 deletions library/think/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use ReflectionMethod;
use think\exception\ClassNotFoundException;
use think\exception\FuncNotFoundException;
use Traversable;

/**
* @package think
Expand Down Expand Up @@ -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);
}
Expand Down
7 changes: 5 additions & 2 deletions library/think/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
16 changes: 11 additions & 5 deletions library/think/Paginator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -341,7 +341,8 @@ public function each(callable $callback)
* @return Traversable An instance of an object implementing <b>Iterator</b> or
* <b>Traversable</b>
*/
public function getIterator()
#[\ReturnTypeWillChange]
public function getIterator(): Traversable
{
return new ArrayIterator($this->items->all());
}
Expand 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);
}
Expand All @@ -363,6 +365,7 @@ public function offsetExists($offset)
* @param mixed $offset
* @return mixed
*/
#[\ReturnTypeWillChange]
public function offsetGet($offset)
{
return $this->items->offsetGet($offset);
Expand All @@ -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);
Expand All @@ -386,6 +390,7 @@ public function offsetSet($offset, $value)
* @return void
* @since 5.0.0
*/
#[\ReturnTypeWillChange]
public function offsetUnset($offset)
{
$this->items->offsetUnset($offset);
Expand All @@ -394,7 +399,7 @@ public function offsetUnset($offset)
/**
* Count elements of an object
*/
public function count()
public function count(): int
{
return $this->items->count();
}
Expand All @@ -404,7 +409,7 @@ public function __toString()
return (string) $this->render();
}

public function toArray()
public function toArray(): array
{
try {
$total = $this->total();
Expand All @@ -424,6 +429,7 @@ public function toArray()
/**
* Specify data which should be serialized to JSON
*/
#[\ReturnTypeWillChange]
public function jsonSerialize()
{
return $this->toArray();
Expand Down
2 changes: 1 addition & 1 deletion library/think/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion library/think/model/concern/Conversion.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ public function __toString()
return $this->toJson();
}

// JsonSerializable
#[\ReturnTypeWillChange]
public function jsonSerialize()
{
return $this->toArray();
Expand Down

0 comments on commit 8619dab

Please sign in to comment.