WordPress.org

Make WordPress Core

Ticket #53635: 53635-WP_Hook-iterator-arrayaccess.patch

File 53635-WP_Hook-iterator-arrayaccess.patch, 3.3 KB (added by jrf, 2 months ago)

Fix various "Deprecated: Return type of WP_Hook::[METHODNAME]() should either be compatible with ...., or the #[ReturnTypeWillChange] attribute should be used to temporarily suppress the notice"

  • src/wp-includes/class-wp-hook.php

    From 44417765ecda8602296d5e8474152175464d63b5 Mon Sep 17 00:00:00 2001
    From: jrfnl <jrfnl@users.noreply.github.com>
    Date: Fri, 23 Jul 2021 03:12:26 +0200
    Subject: [PATCH 1/2] PHP 8.1: WP_Hook: silence return type missing deprecation
     warning
    MIME-Version: 1.0
    Content-Type: text/plain; charset=UTF-8
    Content-Transfer-Encoding: 8bit
    
    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) òr need to silence the deprecation warning using an attribute.
    ---
     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 b final class WP_Hook implements Iterator, ArrayAccess { 
    437437         * @param mixed $offset An offset to check for.
    438438         * @return bool True if the offset exists, false otherwise.
    439439         */
     440        #[ReturnTypeWillChange]
    440441        public function offsetExists( $offset ) {
    441442                return isset( $this->callbacks[ $offset ] );
    442443        }
    final class WP_Hook implements Iterator, ArrayAccess { 
    451452         * @param mixed $offset The offset to retrieve.
    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;
    456458        }
    final class WP_Hook implements Iterator, ArrayAccess { 
    465467         * @param mixed $offset The offset to assign the value to.
    466468         * @param mixed $value The value to set.
    467469         */
     470        #[ReturnTypeWillChange]
    468471        public function offsetSet( $offset, $value ) {
    469472                if ( is_null( $offset ) ) {
    470473                        $this->callbacks[] = $value;
    final class WP_Hook implements Iterator, ArrayAccess { 
    482485         *
    483486         * @param mixed $offset The offset to unset.
    484487         */
     488        #[ReturnTypeWillChange]
    485489        public function offsetUnset( $offset ) {
    486490                unset( $this->callbacks[ $offset ] );
    487491        }
    final class WP_Hook implements Iterator, ArrayAccess { 
    495499         *
    496500         * @return array Of callbacks at current priority.
    497501         */
     502        #[ReturnTypeWillChange]
    498503        public function current() {
    499504                return current( $this->callbacks );
    500505        }
    final class WP_Hook implements Iterator, ArrayAccess { 
    508513         *
    509514         * @return array Of callbacks at next priority.
    510515         */
     516        #[ReturnTypeWillChange]
    511517        public function next() {
    512518                return next( $this->callbacks );
    513519        }
    final class WP_Hook implements Iterator, ArrayAccess { 
    521527         *
    522528         * @return mixed Returns current priority on success, or NULL on failure
    523529         */
     530        #[ReturnTypeWillChange]
    524531        public function key() {
    525532                return key( $this->callbacks );
    526533        }
    final class WP_Hook implements Iterator, ArrayAccess { 
    534541         *
    535542         * @return bool Whether the current position is valid.
    536543         */
     544        #[ReturnTypeWillChange]
    537545        public function valid() {
    538546                return key( $this->callbacks ) !== null;
    539547        }
    final class WP_Hook implements Iterator, ArrayAccess { 
    545553         *
    546554         * @link https://www.php.net/manual/en/iterator.rewind.php
    547555         */
     556        #[ReturnTypeWillChange]
    548557        public function rewind() {
    549558                reset( $this->callbacks );
    550559        }