Skip to content

Commit 132c1b2

Browse files
committed
Fixed #846 // PHP 8.1 compatibility bug
1 parent 4b1940e commit 132c1b2

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

lib/Phpfastcache/Util/ArrayObject.php

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class ArrayObject implements ArrayAccess, Iterator, Countable
3030
/**
3131
* @var array
3232
*/
33-
private $array = [];
33+
private $array;
3434

3535
/**
3636
* @var int
@@ -57,7 +57,7 @@ public function current()
5757
/**
5858
*
5959
*/
60-
public function next()
60+
public function next(): void
6161
{
6262
++$this->position;
6363
}
@@ -90,7 +90,7 @@ public function offsetExists($offset): bool
9090
/**
9191
*
9292
*/
93-
public function rewind()
93+
public function rewind(): void
9494
{
9595
$this->position = 0;
9696
}
@@ -105,8 +105,9 @@ public function count(): int
105105

106106
/**
107107
* @param mixed $offset
108-
* @return mixed|null
108+
* @return mixed
109109
*/
110+
#[\ReturnTypeWillChange] // PHP 8 compatibility
110111
public function offsetGet($offset)
111112
{
112113
return $this->array[$offset] ?? null;
@@ -116,7 +117,7 @@ public function offsetGet($offset)
116117
* @param mixed $offset
117118
* @param mixed $value
118119
*/
119-
public function offsetSet($offset, $value)
120+
public function offsetSet($offset, $value): void
120121
{
121122
// NOTE: THIS IS THE FIX FOR THE ISSUE "Indirect modification of overloaded element of SplFixedArray has no effect"
122123
// NOTE: WHEN APPENDING AN ARRAY (E.G. myArr[] = 5) THE KEY IS NULL, SO WE TEST FOR THIS CONDITION BELOW, AND VOILA
@@ -131,15 +132,15 @@ public function offsetSet($offset, $value)
131132
/**
132133
* @param mixed $offset
133134
*/
134-
public function offsetUnset($offset)
135+
public function offsetUnset($offset): void
135136
{
136137
unset($this->array[$offset]);
137138
}
138139

139140
/**
140-
* @return array|mixed
141+
* @return array
141142
*/
142-
public function toArray()
143+
public function toArray(): array
143144
{
144145
return $this->array;
145146
}
@@ -148,18 +149,18 @@ public function toArray()
148149
* @param array $array
149150
* @return self
150151
*/
151-
public function mergeArray($array): self
152+
public function mergeArray(array $array): self
152153
{
153154
$this->array = array_merge($this->array, $array);
154155

155156
return $this;
156157
}
157158

158159
/**
159-
* @return array|mixed
160+
* @return array
160161
*/
161-
protected function &getArray()
162+
protected function &getArray(): array
162163
{
163164
return $this->array;
164165
}
165-
}
166+
}

0 commit comments

Comments
 (0)