Make WordPress Core

Opened 3 years ago

Closed 2 years ago

#57332 closed defect (bug) (invalid)

setcookie() not working with null

Reported by: kikanirita's profile kikanirita Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: General Keywords: reporter-feedback php81 close
Focuses: Cc:

Description (last modified by sabernhardt)

After upgrade PHP 8.1+, I cannot pass null value in setcookie().
I got the error in my site Deprecated: setcookie(): Passing null to parameter #2 ($value) of type string is deprecated in...

Change History (5)

#1 @costdev
3 years ago

  • Keywords reporter-feedback added

Hi @kikanirita, welcome to Trac!

Can you provide more information about which file causes this issue? (i.e. the "in..." part)

For confidentiality, you can remove anything before the wp-admin, wp-includes, wp-content part of the file path when posting this.

Also, which version of WordPress does your website use? You can find this by navigating to Dashboard > Updates in the WordPress administration area.

Thanks!

#2 @sabernhardt
3 years ago

  • Description modified (diff)
  • Keywords php81 added

#3 @jrf
3 years ago

  • Keywords close added

`setcookie()` is a PHP native function and never allowed the null value, it was just that PHP was tolerant about it and "juggled" null to the expected type.

In other words: that code was always wrong and should be fixed.

As of PHP 8.1, PHP has deprecated the tolerance for passing a `null` value where it is not expected or allowed.

This has literally nothing to do with WordPress.

Considering the phrasing of the report "I cannot pass null value to setcookie()", this sounds like developer error and I would like to suggest you keep up with changes in PHP and - as a minimum - read the migration guide.

If this would be a deprecation which is coming from code within WordPress, a backtrace is needed to find out where the offending code is.

As things stand, however, this doesn't sound like a WP issue.

Suggest: close.

#4 @SergeyBiryukov
3 years ago

Hi there, thanks for the ticket!

Does the issue still happen with all plugins disabled and a default theme (Twenty Twenty-Three) activated?

As noted above, it would be helpful to know whether the issue is with a plugin or theme passing a null value to setcookie(), or if that happens somewhere in WordPress core itself.

A related issue was fixed for WordPress 6.1 in [53490] / #54914.

#5 @hellofromTonya
2 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Status changed from new to closed

Given this ticket is a closed candidate for setcookie() being a PHP native function and there's been no reporter followup to provide more information, I'll close it.

Hello @kikanirita,

Does this problem still happen for you today? If yes, can you please check if happens with a default setup:

Does the issue still happen with all plugins disabled and a default theme (Twenty Twenty-Three) activated?

If yes, then please reopen this ticket and provide as much information as you can to help contributors investigate.

Thank you! :)

Note: See TracTickets for help on using tickets.