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.
Built from https://develop.svn.wordpress.org/trunk@51532


git-svn-id: http://core.svn.wordpress.org/trunk@51143 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Sergey Biryukov 2021-08-03 11:12:55 +00:00
parent 68ba315d9a
commit fedcc33d27
2 changed files with 11 additions and 1 deletions

View File

@ -72,6 +72,7 @@ class WP_Block_List implements Iterator, ArrayAccess, Countable {
* @param string $index Index of block to check. * @param string $index Index of block to check.
* @return bool Whether block exists. * @return bool Whether block exists.
*/ */
#[ReturnTypeWillChange]
public function offsetExists( $index ) { public function offsetExists( $index ) {
return isset( $this->blocks[ $index ] ); return isset( $this->blocks[ $index ] );
} }
@ -86,6 +87,7 @@ class WP_Block_List implements Iterator, ArrayAccess, Countable {
* @param string $index Index of block value to retrieve. * @param string $index Index of block value to retrieve.
* @return mixed|null Block value if exists, or null. * @return mixed|null Block value if exists, or null.
*/ */
#[ReturnTypeWillChange]
public function offsetGet( $index ) { public function offsetGet( $index ) {
$block = $this->blocks[ $index ]; $block = $this->blocks[ $index ];
@ -107,6 +109,7 @@ class WP_Block_List implements Iterator, ArrayAccess, Countable {
* @param string $index Index of block value to set. * @param string $index Index of block value to set.
* @param mixed $value Block value. * @param mixed $value Block value.
*/ */
#[ReturnTypeWillChange]
public function offsetSet( $index, $value ) { public function offsetSet( $index, $value ) {
if ( is_null( $index ) ) { if ( is_null( $index ) ) {
$this->blocks[] = $value; $this->blocks[] = $value;
@ -124,6 +127,7 @@ class WP_Block_List implements Iterator, ArrayAccess, Countable {
* *
* @param string $index Index of block value to unset. * @param string $index Index of block value to unset.
*/ */
#[ReturnTypeWillChange]
public function offsetUnset( $index ) { public function offsetUnset( $index ) {
unset( $this->blocks[ $index ] ); unset( $this->blocks[ $index ] );
} }
@ -135,6 +139,7 @@ class WP_Block_List implements Iterator, ArrayAccess, Countable {
* *
* @link https://www.php.net/manual/en/iterator.rewind.php * @link https://www.php.net/manual/en/iterator.rewind.php
*/ */
#[ReturnTypeWillChange]
public function rewind() { public function rewind() {
reset( $this->blocks ); reset( $this->blocks );
} }
@ -148,6 +153,7 @@ class WP_Block_List implements Iterator, ArrayAccess, Countable {
* *
* @return mixed Current element. * @return mixed Current element.
*/ */
#[ReturnTypeWillChange]
public function current() { public function current() {
return $this->offsetGet( $this->key() ); return $this->offsetGet( $this->key() );
} }
@ -161,6 +167,7 @@ class WP_Block_List implements Iterator, ArrayAccess, Countable {
* *
* @return mixed Key of the current element. * @return mixed Key of the current element.
*/ */
#[ReturnTypeWillChange]
public function key() { public function key() {
return key( $this->blocks ); return key( $this->blocks );
} }
@ -172,6 +179,7 @@ class WP_Block_List implements Iterator, ArrayAccess, Countable {
* *
* @link https://www.php.net/manual/en/iterator.next.php * @link https://www.php.net/manual/en/iterator.next.php
*/ */
#[ReturnTypeWillChange]
public function next() { public function next() {
next( $this->blocks ); next( $this->blocks );
} }
@ -183,6 +191,7 @@ class WP_Block_List implements Iterator, ArrayAccess, Countable {
* *
* @link https://www.php.net/manual/en/iterator.valid.php * @link https://www.php.net/manual/en/iterator.valid.php
*/ */
#[ReturnTypeWillChange]
public function valid() { public function valid() {
return null !== key( $this->blocks ); return null !== key( $this->blocks );
} }
@ -196,6 +205,7 @@ class WP_Block_List implements Iterator, ArrayAccess, Countable {
* *
* @return int Block count. * @return int Block count.
*/ */
#[ReturnTypeWillChange]
public function count() { public function count() {
return count( $this->blocks ); return count( $this->blocks );
} }

View File

@ -13,7 +13,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '5.9-alpha-51531'; $wp_version = '5.9-alpha-51532';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.