From 3e642327cc3916fc7d45b0931effb73adeaa7385 Mon Sep 17 00:00:00 2001
From: jrfnl <jrfnl@users.noreply.github.com>
Date: Tue, 11 Aug 2020 23:21:50 +0200
Subject: [PATCH] PHP 8.0: fix fatal "argument must be passed by reference,
value given" [1]
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 a fatal `arguments must be passed by reference, value given` error.
The PHP native `array_walk()` function _does_ pass by reference. Using this prevents the fatal error on PHP 8 and maintains the existing behaviour on PHP < 8.
This patch fixes 96 errors + 62 failures + 3 warnings of the test failures on PHP 8.
Refs:
* https://developer.wordpress.org/reference/functions/get_comment/
* https://www.php.net/manual/en/function.array-map.php
* https://www.php.net/manual/en/function.array-walk.php
---
src/wp-includes/class-wp-comment-query.php | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/src/wp-includes/class-wp-comment-query.php b/src/wp-includes/class-wp-comment-query.php
index bbc6fe2d66..e185ceb40e 100644
|
a
|
b
|
class WP_Comment_Query { |
| 481 | 481 | $_comments = apply_filters_ref_array( 'the_comments', array( $_comments, &$this ) ); |
| 482 | 482 | |
| 483 | 483 | // Convert to WP_Comment instances. |
| 484 | | $comments = array_map( 'get_comment', $_comments ); |
| | 484 | array_walk( $_comments, 'get_comment' ); |
| | 485 | $comments = $_comments; |
| 485 | 486 | |
| 486 | 487 | if ( $this->query_vars['hierarchical'] ) { |
| 487 | 488 | $comments = $this->fill_descendants( $comments ); |