Skip to content

Commit fb6cb64

Browse files
committed
PHP 8.1: ms_cookie_constants(): prevent "passing null to non-nullable" notice
It is entirely possible for the `siteurl` option to not have a "path" component. In PHP 8.1, this would lead to a `trim(): Passing null to parameter #1 ($string) of type string is deprecated` deprecation notice. Changing the logic around and adding validation for the return type value of `parse_url()` prevents that. Unfortunately, as this function is declaring global constants, adding tests for this change is not really an option without potentially affecting other tests. Also note, that it is possible, though unlikely, for the option to not be available. In that case though, the `get_option()` method returns `false` and while passing that to `parse_url()` does not deserve any prices for clean code, it also is not problematic (at this point in time).
1 parent 6592d67 commit fb6cb64

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/wp-includes/ms-default-constants.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ function ms_cookie_constants() {
6868
* @since 2.6.0
6969
*/
7070
if ( ! defined( 'ADMIN_COOKIE_PATH' ) ) {
71-
if ( ! is_subdomain_install() || trim( parse_url( get_option( 'siteurl' ), PHP_URL_PATH ), '/' ) ) {
71+
$site_path = parse_url( get_option( 'siteurl' ), PHP_URL_PATH );
72+
if ( ! is_subdomain_install() || ( is_string( $site_path ) && trim( $site_path, '/' ) ) ) {
7273
define( 'ADMIN_COOKIE_PATH', SITECOOKIEPATH );
7374
} else {
7475
define( 'ADMIN_COOKIE_PATH', SITECOOKIEPATH . 'wp-admin' );

0 commit comments

Comments
 (0)