Make WordPress Core

Opened 2 years ago

Closed 2 years ago

Last modified 2 years ago

#54914 closed defect (bug) (fixed)

Deprecation warning for PHP 8.1 setcookie

Reported by: shenyanzhi's profile shenyanzhi Owned by: sergeybiryukov's profile SergeyBiryukov
Milestone: 6.1 Priority: normal
Severity: normal Version: 4.0
Component: Options, Meta APIs Keywords: php81 has-patch
Focuses: Cc:

Description (last modified by sabernhardt)

Deprecated: setcookie(): Passing null to parameter #5 ($domain) of type string is deprecated in .../wp-includes/option.php on line 1109

Change History (7)

#1 @costdev
2 years ago

  • Keywords php81 added

#2 @sabernhardt
2 years ago

  • Description modified (diff)

This ticket was mentioned in PR #2800 on WordPress/wordpress-develop by ocean90.


2 years ago
#3

  • Keywords has-patch added

$domain should be a string and not null to avoid the PHP 8.2 deprecation: _setcookie():
Passing null to parameter #5 ($domain) of type string is deprecated_

Introduced in https://github.com/WordPress/wordpress-develop/commit/b343d482215025aa7da34c71219796361b9b4f7e / https://core.trac.wordpress.org/changeset/29478.

Trac ticket: https://core.trac.wordpress.org/ticket/54914

#4 @ocean90
2 years ago

  • Component changed from General to Options, Meta APIs
  • Milestone changed from Awaiting Review to 6.1
  • Severity changed from major to normal
  • Version changed from 5.9 to 4.0

#5 @SergeyBiryukov
2 years ago

  • Owner set to SergeyBiryukov
  • Resolution set to fixed
  • Status changed from new to closed

In 53490:

Code Modernization: Pass correct default value to setcookie() in wp_user_settings().

The wp_user_settings() function calls the PHP native setcookie() function, the fifth parameter of which is the optional $domain parameter which expects a string.

A parameter being optional, however, does not automatically make it nullable.

As of PHP 8.1, passing null to a non-nullable PHP native function will generate a deprecation notice.

In this case, this function call yielded a setcookie(): Passing null to parameter #5 ($domain) of type string is deprecated notice.

Changing the null to an empty string fixes this without a backward compatibility break.

References:

Follow-up to [29478].

Props ocean90, shenyanzhi, meysamnorouzi, jrf.
Fixes #54914.

#7 @SergeyBiryukov
2 years ago

In 53493:

Tests: Add a unit test for PHP 8.1 deprecation notice in wp_user_settings().

This ensures that PHP 8.1 "passing null to non-nullable" deprecation notice is not thrown for the $domain parameter of setcookie() calls in the function.

Follow-up to [53490].

See #54914.

Note: See TracTickets for help on using tickets.