Fix str_starts_with() null deprecation in get_current_url_supercache_dir#851
Closed
davidcarma wants to merge 1 commit intoAutomattic:trunkfrom
Closed
Fix str_starts_with() null deprecation in get_current_url_supercache_dir#851davidcarma wants to merge 1 commit intoAutomattic:trunkfrom
davidcarma wants to merge 1 commit intoAutomattic:trunkfrom
Conversation
On PHP 8.1+, passing null to str_starts_with() as the $needle parameter triggers a deprecation notice. The global $wp_cache_home_path can be null when it is not defined in the cache config, causing: Deprecated: str_starts_with(): Passing null to parameter #2 ($needle) of type string is deprecated in wp-cache-phase2.php on line 857 This coalesces $wp_cache_home_path to an empty string and skips the prefix check entirely when the home path is empty, which avoids both the deprecation warning and the incorrect rtrim(null, '/') call inside the conditional body. Made-with: Cursor
|
Thank you for your interest! Pull requests should be made against the monorepo at https://github.com/Automattic/jetpack. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Summary
str_starts_with(): Passing null to parameter #2 ($needle) of type string is deprecatedon line 857 ofwp-cache-phase2.php$wp_cache_home_pathcan be null when not defined in the cache config, which gets passed directly tostr_starts_with()andrtrim()as a null needle/characters parameter$wp_cache_home_pathto an empty string and skips the prefix check entirely when the home path is empty, avoiding both the deprecation and the semantically incorrectrtrim(null, '/')callReproduction
$wp_cache_home_pathis not set in the cache configChanges
Notes
$wp_cache_request_uripassed toesc_url_raw()on line 394$wp_cache_home_pathis properly setMade with Cursor