Skip to content

Commit 9f3c2be

Browse files
Code Modernization: Silence the deprecation warnings for missing return type in WP_Block_List.
This fixes the "Deprecated: Return type of `WP_Block_List::[METHODNAME]()` should be compatible with `ArrayAccess::[METHODNAME](): type`" warnings on PHP 8.1. PHP native interfaces now have declared return types and methods in classes implementing these interfaces need to either have the return type declared (in a covariant compatible manner with the PHP native interface method declaration), or need to silence the deprecation warning using the `#[ReturnTypeWillChange]` attribute. Follow-up to [51517], [51529], [51530], [51531]. Props jrf. See #53635. git-svn-id: https://develop.svn.wordpress.org/trunk@51532 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 289c9c7 commit 9f3c2be

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/wp-includes/class-wp-block-list.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ public function __construct( $blocks, $available_context = array(), $registry =
7272
* @param string $index Index of block to check.
7373
* @return bool Whether block exists.
7474
*/
75+
#[ReturnTypeWillChange]
7576
public function offsetExists( $index ) {
7677
return isset( $this->blocks[ $index ] );
7778
}
@@ -86,6 +87,7 @@ public function offsetExists( $index ) {
8687
* @param string $index Index of block value to retrieve.
8788
* @return mixed|null Block value if exists, or null.
8889
*/
90+
#[ReturnTypeWillChange]
8991
public function offsetGet( $index ) {
9092
$block = $this->blocks[ $index ];
9193

@@ -107,6 +109,7 @@ public function offsetGet( $index ) {
107109
* @param string $index Index of block value to set.
108110
* @param mixed $value Block value.
109111
*/
112+
#[ReturnTypeWillChange]
110113
public function offsetSet( $index, $value ) {
111114
if ( is_null( $index ) ) {
112115
$this->blocks[] = $value;
@@ -124,6 +127,7 @@ public function offsetSet( $index, $value ) {
124127
*
125128
* @param string $index Index of block value to unset.
126129
*/
130+
#[ReturnTypeWillChange]
127131
public function offsetUnset( $index ) {
128132
unset( $this->blocks[ $index ] );
129133
}
@@ -135,6 +139,7 @@ public function offsetUnset( $index ) {
135139
*
136140
* @link https://www.php.net/manual/en/iterator.rewind.php
137141
*/
142+
#[ReturnTypeWillChange]
138143
public function rewind() {
139144
reset( $this->blocks );
140145
}
@@ -148,6 +153,7 @@ public function rewind() {
148153
*
149154
* @return mixed Current element.
150155
*/
156+
#[ReturnTypeWillChange]
151157
public function current() {
152158
return $this->offsetGet( $this->key() );
153159
}
@@ -161,6 +167,7 @@ public function current() {
161167
*
162168
* @return mixed Key of the current element.
163169
*/
170+
#[ReturnTypeWillChange]
164171
public function key() {
165172
return key( $this->blocks );
166173
}
@@ -172,6 +179,7 @@ public function key() {
172179
*
173180
* @link https://www.php.net/manual/en/iterator.next.php
174181
*/
182+
#[ReturnTypeWillChange]
175183
public function next() {
176184
next( $this->blocks );
177185
}
@@ -183,6 +191,7 @@ public function next() {
183191
*
184192
* @link https://www.php.net/manual/en/iterator.valid.php
185193
*/
194+
#[ReturnTypeWillChange]
186195
public function valid() {
187196
return null !== key( $this->blocks );
188197
}
@@ -196,6 +205,7 @@ public function valid() {
196205
*
197206
* @return int Block count.
198207
*/
208+
#[ReturnTypeWillChange]
199209
public function count() {
200210
return count( $this->blocks );
201211
}

0 commit comments

Comments
 (0)