Make WordPress Core

Changeset 51530


Ignore:
Timestamp:
08/03/2021 11:00:50 AM (3 years ago)
Author:
SergeyBiryukov
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-hook.php

    r50811 r51530  
    438438     * @return bool True if the offset exists, false otherwise.
    439439     */
     440    #[ReturnTypeWillChange]
    440441    public function offsetExists( $offset ) {
    441442        return isset( $this->callbacks[ $offset ] );
     
    452453     * @return mixed If set, the value at the specified offset, null otherwise.
    453454     */
     455    #[ReturnTypeWillChange]
    454456    public function offsetGet( $offset ) {
    455457        return isset( $this->callbacks[ $offset ] ) ? $this->callbacks[ $offset ] : null;
     
    466468     * @param mixed $value The value to set.
    467469     */
     470    #[ReturnTypeWillChange]
    468471    public function offsetSet( $offset, $value ) {
    469472        if ( is_null( $offset ) ) {
     
    483486     * @param mixed $offset The offset to unset.
    484487     */
     488    #[ReturnTypeWillChange]
    485489    public function offsetUnset( $offset ) {
    486490        unset( $this->callbacks[ $offset ] );
     
    496500     * @return array Of callbacks at current priority.
    497501     */
     502    #[ReturnTypeWillChange]
    498503    public function current() {
    499504        return current( $this->callbacks );
     
    509514     * @return array Of callbacks at next priority.
    510515     */
     516    #[ReturnTypeWillChange]
    511517    public function next() {
    512518        return next( $this->callbacks );
     
    522528     * @return mixed Returns current priority on success, or NULL on failure
    523529     */
     530    #[ReturnTypeWillChange]
    524531    public function key() {
    525532        return key( $this->callbacks );
     
    535542     * @return bool Whether the current position is valid.
    536543     */
     544    #[ReturnTypeWillChange]
    537545    public function valid() {
    538546        return key( $this->callbacks ) !== null;
     
    546554     * @link https://www.php.net/manual/en/iterator.rewind.php
    547555     */
     556    #[ReturnTypeWillChange]
    548557    public function rewind() {
    549558        reset( $this->callbacks );
Note: See TracChangeset for help on using the changeset viewer.