Skip to:
Content

BuddyPress.org

Changeset 13311


Ignore:
Timestamp:
08/09/2022 06:23:32 PM (20 months ago)
Author:
imath
Message:

Avoid PHP 8.1 ArrayAccess Return Type deprecation notices

The BP_Core_BP_Nav_BackCompat is implementing the ArrayAccess class to provide backward compatibility to BuddyPress plugins directly modifying the buddypress()->bp_nav global since BuddyPress 2.3.

PHP 8.1 added a deprecation notice if a class declaration has an incompatible return type (or if the return type lacks: which is the case for BP_Core_BP_Nav_BackCompat) with the parent it extends.

As BuddyPress supports PHP back to version 5.6, we need to use the #ReturnTypeWillChange attribute to maintain compatibility with this version and avoid the deprecation notice in PHP 8.x.

Fixes #8726

Location:
trunk/src/bp-core
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-core/bp-core-avatars.php

    r13215 r13311  
    457457    // Use an alias to leave the param unchanged.
    458458    $avatar_classes = $params['class'];
    459     if ( ! is_array( $avatar_classes ) ) {
     459    if ( is_null( $avatar_classes ) ) {
     460        $avatar_classes = array();
     461    } elseif ( ! is_array( $avatar_classes ) ) {
    460462        $avatar_classes = explode( ' ', $avatar_classes );
    461463    }
  • trunk/src/bp-core/classes/class-bp-core-bp-nav-backcompat.php

    r11447 r13311  
    6161     * @param array $value  Nav item.
    6262     */
     63    #[ReturnTypeWillChange]
    6364    public function offsetSet( $offset, $value ) {
    6465        _doing_it_wrong(
     
    9596     * @return BP_Core_BP_Nav_BackCompat
    9697     */
     98    #[ReturnTypeWillChange]
    9799    public function offsetGet( $offset ) {
    98100        _doing_it_wrong(
     
    102104        );
    103105
    104 //      if ( ! isset( $this->backcompat_nav[ $offset ] ) ) {
    105             $nav = $this->get_nav( $offset );
    106             if ( $nav && isset( $nav[ $offset ] ) ) {
    107                 $this->backcompat_nav[ $offset ] = new self( $nav[ $offset ] );
    108             }
    109 //      }
     106        $nav = $this->get_nav( $offset );
     107        if ( $nav && isset( $nav[ $offset ] ) ) {
     108            $this->backcompat_nav[ $offset ] = new self( $nav[ $offset ] );
     109        }
    110110
    111111        return $this->backcompat_nav[ $offset ];
     
    120120     * @return bool
    121121     */
     122    #[ReturnTypeWillChange]
    122123    public function offsetExists( $offset ) {
    123124        _doing_it_wrong(
     
    146147     * @param mixed $offset Array offset.
    147148     */
     149    #[ReturnTypeWillChange]
    148150    public function offsetUnset( $offset ) {
    149151        _doing_it_wrong(
Note: See TracChangeset for help on using the changeset viewer.