From 471edb01939328d2858ac31e20625c95ff7163bb Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Tue, 3 Aug 2021 11:00:50 +0000 Subject: [PATCH] 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. git-svn-id: https://develop.svn.wordpress.org/trunk@51530 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/class-wp-hook.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/wp-includes/class-wp-hook.php b/src/wp-includes/class-wp-hook.php index 432a01600f..cb49271ba4 100644 --- a/src/wp-includes/class-wp-hook.php +++ b/src/wp-includes/class-wp-hook.php @@ -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 ); }