Make WordPress Core

Ticket #50913: 50913-3-po-pass-by-ref-fix.patch

File 50913-3-po-pass-by-ref-fix.patch, 2.3 KB (added by jrf, 3 years ago)

Fixes another "argument # must be passed by reference" issue - see the PR for more information and a passing build + see https://3v4l.org/KbpLJ for proof of issue

  • src/wp-includes/pomo/po.php

    From ebbe386b13335ae3efd168aac5a88c13d32c9367 Mon Sep 17 00:00:00 2001
    From: jrfnl <jrfnl@users.noreply.github.com>
    Date: Sun, 18 Oct 2020 00:56:03 +0200
    Subject: [PATCH] PHP 8.0: fix "argument # must be passed by reference" warning
    
    WordPress should not throw any notices.
    
    `array_map()` passes by value, while `array_walk()` passes by reference.
    
    The use of `array_map()` on line 52 within the `export_entries()` method will cause a "Warning: PO::export_entry(): Argument #1 ($entry) must be passed by reference, value given" warning on PHP 8.0 because the `export_entry()` method is declared to expect the `$entry` object to be passed by reference.
    
    Since PHP 5.0, objects are passed by reference by default and this does not have to be declared in the function signature of a method expecting this anymore.
    
    Also, the code within the method doesn't even try to change `$entry` and return a value.
    
    So, all in all, the reference in the function declaration is redundant, old-school and should be removed.
    
    While this could be considered a BC-break, I have done a search for use of this method in plugins and reviewed a significant number of the returned results. None of these would run into trouble with the change now made. Rather this change fixes the same issue for a number of plugins also using `array_map()`.
    
    All the same, this change should be mentioned in a dev-note as it is a very small and insignificant BC-break.
    
    Search results: https://wpdirectory.net/search/01EMWBEKAM2B6ECSTCTEDAZGQW
    ---
     src/wp-includes/pomo/po.php | 4 ++--
     1 file changed, 2 insertions(+), 2 deletions(-)
    
    diff --git a/src/wp-includes/pomo/po.php b/src/wp-includes/pomo/po.php
    index b2a605a3ec..99bb6891b1 100644
    a b if ( ! class_exists( 'PO', false ) ) : 
    212212                /**
    213213                 * Builds a string from the entry for inclusion in PO file
    214214                 *
    215                  * @param Translation_Entry $entry the entry to convert to po string (passed by reference).
     215                 * @param Translation_Entry $entry the entry to convert to po string.
    216216                 * @return string|false PO-style formatted string for the entry or
    217217                 *  false if the entry is empty
    218218                 */
    219                 public static function export_entry( &$entry ) {
     219                public static function export_entry( $entry ) {
    220220                        if ( null === $entry->singular || '' === $entry->singular ) {
    221221                                return false;
    222222                        }