#57578 closed defect (bug) (fixed)
Deprecated preg_replace() warning PHP 8.1
Reported by: |
|
Owned by: |
|
---|---|---|---|
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)
Change History (7)
#2
follow-up:
↓ 3
@
2 years ago
- Component changed from General to Administration
- Keywords has-patch added
- Milestone changed from Awaiting Review to 6.2
#3
in reply to:
↑ 2
;
follow-up:
↓ 4
@
2 years 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
@
2 years 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 :)
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 causesget_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, andget_plugin_page_hookname()
receivesnull
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.