Code Modernization: Silence the deprecation warnings for missing return type in `WP_Hook`.

This fixes the "Deprecated: Return type of `WP_Hook::[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].

Props jrf.
See #53635.
Built from https://develop.svn.wordpress.org/trunk@51530


git-svn-id: http://core.svn.wordpress.org/trunk@51141 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Sergey Biryukov 2021-08-03 11:02:00 +00:00
parent 3c14324dc6
commit 85c1413c2b
2 changed files with 10 additions and 1 deletions

View File

@ -437,6 +437,7 @@ final class WP_Hook implements Iterator, ArrayAccess {
* @param mixed $offset An offset to check for.
* @return bool True if the offset exists, false otherwise.
*/
#[ReturnTypeWillChange]
public function offsetExists( $offset ) {
return isset( $this->callbacks[ $offset ] );
}
@ -451,6 +452,7 @@ final class WP_Hook implements Iterator, ArrayAccess {
* @param mixed $offset The offset to retrieve.
* @return mixed If set, the value at the specified offset, null otherwise.
*/
#[ReturnTypeWillChange]
public function offsetGet( $offset ) {
return isset( $this->callbacks[ $offset ] ) ? $this->callbacks[ $offset ] : null;
}
@ -465,6 +467,7 @@ final class WP_Hook implements Iterator, ArrayAccess {
* @param mixed $offset The offset to assign the value to.
* @param mixed $value The value to set.
*/
#[ReturnTypeWillChange]
public function offsetSet( $offset, $value ) {
if ( is_null( $offset ) ) {
$this->callbacks[] = $value;
@ -482,6 +485,7 @@ final class WP_Hook implements Iterator, ArrayAccess {
*
* @param mixed $offset The offset to unset.
*/
#[ReturnTypeWillChange]
public function offsetUnset( $offset ) {
unset( $this->callbacks[ $offset ] );
}
@ -495,6 +499,7 @@ final class WP_Hook implements Iterator, ArrayAccess {
*
* @return array Of callbacks at current priority.
*/
#[ReturnTypeWillChange]
public function current() {
return current( $this->callbacks );
}
@ -508,6 +513,7 @@ final class WP_Hook implements Iterator, ArrayAccess {
*
* @return array Of callbacks at next priority.
*/
#[ReturnTypeWillChange]
public function next() {
return next( $this->callbacks );
}
@ -521,6 +527,7 @@ final class WP_Hook implements Iterator, ArrayAccess {
*
* @return mixed Returns current priority on success, or NULL on failure
*/
#[ReturnTypeWillChange]
public function key() {
return key( $this->callbacks );
}
@ -534,6 +541,7 @@ final class WP_Hook implements Iterator, ArrayAccess {
*
* @return bool Whether the current position is valid.
*/
#[ReturnTypeWillChange]
public function valid() {
return key( $this->callbacks ) !== null;
}
@ -545,6 +553,7 @@ final class WP_Hook implements Iterator, ArrayAccess {
*
* @link https://www.php.net/manual/en/iterator.rewind.php
*/
#[ReturnTypeWillChange]
public function rewind() {
reset( $this->callbacks );
}

View File

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