WordPress.org

Make WordPress Core

Changeset 51532


Ignore:
Timestamp:
08/03/2021 11:11:45 AM (8 weeks ago)
Author:
SergeyBiryukov
Message:

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.

File:
1 edited

Legend:

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

    r48845 r51532  
    7373     * @return bool Whether block exists.
    7474     */
     75    #[ReturnTypeWillChange]
    7576    public function offsetExists( $index ) {
    7677        return isset( $this->blocks[ $index ] );
     
    8788     * @return mixed|null Block value if exists, or null.
    8889     */
     90    #[ReturnTypeWillChange]
    8991    public function offsetGet( $index ) {
    9092        $block = $this->blocks[ $index ];
     
    108110     * @param mixed  $value Block value.
    109111     */
     112    #[ReturnTypeWillChange]
    110113    public function offsetSet( $index, $value ) {
    111114        if ( is_null( $index ) ) {
     
    125128     * @param string $index Index of block value to unset.
    126129     */
     130    #[ReturnTypeWillChange]
    127131    public function offsetUnset( $index ) {
    128132        unset( $this->blocks[ $index ] );
     
    136140     * @link https://www.php.net/manual/en/iterator.rewind.php
    137141     */
     142    #[ReturnTypeWillChange]
    138143    public function rewind() {
    139144        reset( $this->blocks );
     
    149154     * @return mixed Current element.
    150155     */
     156    #[ReturnTypeWillChange]
    151157    public function current() {
    152158        return $this->offsetGet( $this->key() );
     
    162168     * @return mixed Key of the current element.
    163169     */
     170    #[ReturnTypeWillChange]
    164171    public function key() {
    165172        return key( $this->blocks );
     
    173180     * @link https://www.php.net/manual/en/iterator.next.php
    174181     */
     182    #[ReturnTypeWillChange]
    175183    public function next() {
    176184        next( $this->blocks );
     
    184192     * @link https://www.php.net/manual/en/iterator.valid.php
    185193     */
     194    #[ReturnTypeWillChange]
    186195    public function valid() {
    187196        return null !== key( $this->blocks );
     
    197206     * @return int Block count.
    198207     */
     208    #[ReturnTypeWillChange]
    199209    public function count() {
    200210        return count( $this->blocks );
Note: See TracChangeset for help on using the changeset viewer.