PHP 8.0: fix "argument # must be passed by reference" warning (Trac: 50913) #618
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
WordPress should not throw any notices.
array_map()
passes by value, whilearray_walk()
passes by reference.The use of
array_map()
on line 52 within theexport_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 theexport_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
Trac ticket: https://core.trac.wordpress.org/ticket/50913
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.