Opened 3 months ago
Last modified 3 months ago
#62950 new defect (bug)
PHP deprecation warning in /wp-admin/includes/class-automatic-upgrader-skin.php
Reported by: |
|
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)
Change History (3)
#1
@
3 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
@
3 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. 🚀
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.