Make WordPress Core

Opened 18 months ago

Closed 18 months ago

Last modified 18 months ago

#57578 closed defect (bug) (fixed)

Deprecated preg_replace() warning PHP 8.1

Reported by: ipajen's profile ipajen Owned by: sergeybiryukov's profile SergeyBiryukov
Milestone: 6.2 Priority: normal
Severity: normal Version: 6.2
Component: Administration Keywords: php81 has-patch
Focuses: Cc:

Description

PHP warning is thrown in 6.2-alpha-55159 with PHP 8.1

/wp-admin/options-privacy.php
/wp-admin/options-privacy.php?tab=policyguide
/wp-admin/export-personal-data.php
/wp-admin/erase-personal-data.php

preg_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated

wp-admin/includes/plugin.php:2088
preg_replace()
wp-admin/includes/plugin.php:2088
get_plugin_page_hookname()
wp-admin/includes/plugin.php:2052
get_plugin_page_hook()
wp-admin/includes/plugin.php:1976
get_admin_page_title()
wp-admin/admin-header.php:35

Attachments (1)

57578.diff (1.9 KB) - added by SergeyBiryukov 18 months ago.

Download all attachments as: .zip

Change History (7)

#1 @costdev
18 months ago

  • Keywords php81 added; PHP 8.1 removed

#2 follow-up: @SergeyBiryukov
18 months ago

  • Component changed from General to Administration
  • Keywords has-patch added
  • Milestone changed from Awaiting Review to 6.2

Hi there, thanks for the ticket!

After some testing, it appears that the notice is only triggered on these privacy screens and not on others because these screens don't set the $title global that exists on other screens. This causes get_admin_page_title(), instead of returning early like on other screens, to continue with retrieving the page title from the menu array. In the process, get_plugin_page_hook() is called, but as these screens are created by core and not by a plugin, the $plugin_page global is not set, and get_plugin_page_hookname() receives null as the first parameter instead of a string.

57578.diff fixes the inconsistency by setting the $title global on the affected screens, since it is apparently assumed to be set on all core administration screens. This resolves the notice in my testing. No new strings are introduced, because these strings match the existing page titles.

#3 in reply to: ↑ 2 ; follow-up: @jrf
18 months ago

Replying to SergeyBiryukov:

57578.diff fixes the inconsistency by setting the $title global on the affected screens, since it is apparently assumed to be set on all core administration screens. This resolves the notice in my testing. No new strings are introduced, because these strings match the existing page titles.

@SergeyBiryukov Sounds like a solid analysis and the correct solution. 👍

Is there anything we could do unit test-wise to safeguard this ? I haven't looked at the code in detail (on my break), but I fear this may be difficult due to it being part of the global page generation code ?

#4 in reply to: ↑ 3 @SergeyBiryukov
18 months ago

Replying to jrf:

Is there anything we could do unit test-wise to safeguard this ? I haven't looked at the code in detail (on my break), but I fear this may be difficult due to it being part of the global page generation code ?

Yeah, it's not immediately clear to me how to write a test case for this. We can follow up later if anyone comes up with an idea :)

#5 @SergeyBiryukov
18 months ago

  • Owner set to SergeyBiryukov
  • Resolution set to fixed
  • Status changed from new to closed

In 55263:

Administration: Define the $title global on privacy screens.

This brings more consistency with other screens and avoids a PHP warning in get_plugin_page_hookname():

preg_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated

Props ipajen, jrf, SergeyBiryukov.
Fixes #57578.

#6 @SergeyBiryukov
18 months ago

#57754 was marked as a duplicate.

Note: See TracTickets for help on using tickets.