Make WordPress Core

Opened 13 months ago

Last modified 10 hours ago

#62950 new defect (bug)

PHP deprecation warning in /wp-admin/includes/class-automatic-upgrader-skin.php

Reported by: nexbridge's profile nexbridge Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 6.7.2
Component: Upgrade/Install Keywords:
Focuses: Cc:

Description

The following warnings are being triggered in the above file when the WordPress version auto-updates.

On line 87:

str_contains(): Passing null to parameter #1 ($haystack) of type string is deprecated

On line 93:

trim(): Passing null to parameter #1 ($string) of type string is deprecated

The PHP version is 8.2.

Attachments (1)

62950.patch (634 bytes) - added by sainathpoojary 13 months ago.
The issue occurred because $string was uninitialized when $feedback was neither an error nor a string, resulting in null being passed to str_contains() and trim(), which is deprecated in PHP 8.2. This fix ensures $string is always initialized as an empty string before use, preventing these warnings.

Download all attachments as: .zip

Change History (5)

@sainathpoojary
13 months ago

The issue occurred because $string was uninitialized when $feedback was neither an error nor a string, resulting in null being passed to str_contains() and trim(), which is deprecated in PHP 8.2. This fix ensures $string is always initialized as an empty string before use, preventing these warnings.

#1 @nexbridge
13 months ago

Thanks @sainathpoojary, but in PHP if a variable is not initialised then it would throw a different warning - the issue here seems to be that the variable is being set to NULL in some cases and this is then causing the deprecation warning when it's passed into str_contains() or trim(). The variable is being set on lines 76, 80 and 84, however judging by the code I doubt that lines 76 or 84 would return a NULL value, so it may be as simple as just adding a null coalescing operator on line 80:

<?php
$string = $feedback ?? '';

To that end I've added some debug lines to test my theory the next time it happens!

#2 @sainathpoojary
13 months ago

Thanks for the clarification! You’re right if the variable were truly uninitialized, we’d expect a different warning. It makes sense that $feedback might explicitly be null in some cases, leading to the deprecation warning when passed into str_contains() or trim(). I’ll test the fix with auto-updates, and if it works as expected, I’ll raise a PR. 🚀

#3 @nexbridge
5 weeks ago

Just to say that this is still happening on the 6.9 branch. I've included stack traces for both the trim() and str_contains() warnings if it helps.

[2026-02-04 04:38:00] str_contains(): Passing null to parameter #1 ($haystack) of type string is deprecated
E_DEPRECATED at /wp-admin/includes/class-automatic-upgrader-skin.php(87):
#0 [internal function]: {closure}()
#1 /wp-admin/includes/class-automatic-upgrader-skin.php(87): str_contains()
#2 /wp-includes/class-wp-hook.php(341): Automatic_Upgrader_Skin->feedback()
#3 /wp-includes/plugin.php(205): WP_Hook->apply_filters()
#4 /wp-admin/includes/update-core.php(1577): apply_filters()
#5 /wp-admin/includes/class-core-upgrader.php(178): update_core()
#6 /wp-admin/includes/class-wp-automatic-updater.php(478): Core_Upgrader->upgrade()
#7 /wp-admin/includes/class-wp-automatic-updater.php(715): WP_Automatic_Updater->update()
#8 /wp-includes/update.php(890): WP_Automatic_Updater->run()
#9 /wp-includes/class-wp-hook.php(341): wp_maybe_auto_update()
#10 /wp-includes/class-wp-hook.php(365): WP_Hook->apply_filters()
#11 /wp-includes/plugin.php(522): WP_Hook->do_action()
#12 /wp-content/plugins/stops-core-theme-and-plugin-updates/includes/MPSUM_Disable_Updates.php(191): do_action()
#13 /wp-includes/class-wp-hook.php(341): MPSUM_Disable_Updates->maybe_auto_update()
#14 /wp-includes/class-wp-hook.php(365): WP_Hook->apply_filters()
#15 /wp-includes/plugin.php(570): WP_Hook->do_action()
#16 /wp-cron.php(191): do_action_ref_array()
#17 {main}
[2026-02-04 04:38:00] trim(): Passing null to parameter #1 ($string) of type string is deprecated
E_DEPRECATED at /wp-admin/includes/class-automatic-upgrader-skin.php(93):
#0 [internal function]: {closure}()
#1 /wp-admin/includes/class-automatic-upgrader-skin.php(93): trim()
#2 /wp-includes/class-wp-hook.php(341): Automatic_Upgrader_Skin->feedback()
#3 /wp-includes/plugin.php(205): WP_Hook->apply_filters()
#4 /wp-admin/includes/update-core.php(1577): apply_filters()
#5 /wp-admin/includes/class-core-upgrader.php(178): update_core()
#6 /wp-admin/includes/class-wp-automatic-updater.php(478): Core_Upgrader->upgrade()
#7 /wp-admin/includes/class-wp-automatic-updater.php(715): WP_Automatic_Updater->update()
#8 /wp-includes/update.php(890): WP_Automatic_Updater->run()
#9 /wp-includes/class-wp-hook.php(341): wp_maybe_auto_update()
#10 /wp-includes/class-wp-hook.php(365): WP_Hook->apply_filters()
#11 /wp-includes/plugin.php(522): WP_Hook->do_action()
#12 /wp-content/plugins/stops-core-theme-and-plugin-updates/includes/MPSUM_Disable_Updates.php(191): do_action()
#13 /wp-includes/class-wp-hook.php(341): MPSUM_Disable_Updates->maybe_auto_update()
#14 /wp-includes/class-wp-hook.php(365): WP_Hook->apply_filters()
#15 /wp-includes/plugin.php(570): WP_Hook->do_action()
#16 /wp-cron.php(191): do_action_ref_array()
#17 {main}

#4 @nexbridge
10 hours ago

Just to add that I've confirmed it's line 80 that's setting a NULL value for $string, implying that the $feedback argument being passed into the feedback() function is NULL.

Note: See TracTickets for help on using tickets.