WordPress.org

Make WordPress Core

Changeset 48838


Ignore:
Timestamp:
08/21/2020 09:32:49 PM (10 months ago)
Author:
SergeyBiryukov
Message:

Code Modernization: Fix PHP 8 "argument must be passed by reference, value given" error in WP_Comment_Query::get_comments().

The WP native get_comment() function expects the first argument $comment to be passed by reference.

The PHP array_map() function, however, passes by value, not by reference, resulting in an "arguments must be passed by reference, value given" error.

The PHP native array_walk() function does pass by reference. Using this prevents the error on PHP 8 and maintains the existing behaviour on PHP < 8.

Props jrf.
See #50913.

File:
1 edited

Legend:

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

    r48782 r48838  
    482482
    483483        // Convert to WP_Comment instances.
    484         $comments = array_map( 'get_comment', $_comments );
     484        array_walk( $_comments, 'get_comment' );
     485        $comments = $_comments;
    485486
    486487        if ( $this->query_vars['hierarchical'] ) {
Note: See TracChangeset for help on using the changeset viewer.