WordPress.org

Make WordPress Core

Opened 7 months ago

Last modified 7 months ago

#46550 new defect (bug)

Uncaught TypeError: setcookie() expects parameter 5 to be string, bool given in...

Reported by: kmvan Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 5.2
Component: Bootstrap/Load Keywords: reporter-feedback
Focuses: Cc:
PR Number:

Description

https://github.com/WordPress/WordPress/blob/5e62e6b2034516c0bb366f808673752030d2d2b7/wp-includes/default-constants.php#L303

<?php
        /**
         * @since 2.0.0
         */
        if ( ! defined( 'COOKIE_DOMAIN' ) ) {
                define( 'COOKIE_DOMAIN', false ); // The value maybe '', not boolean
        }

Change History (2)

#1 @desrosj
7 months ago

  • Keywords reporter-feedback added; needs-patch removed
  • Severity changed from critical to normal

Hi @kmvan,

Your ticket is not very detailed. It's impossible to look into this further without more information.

Are you running a single site install or a multisite install? Where is the call to setcookie()? Is it in WordPress Core? A plugin? A theme? Please provide more details so that others can reproduce your issue.

#2 @kmvan
7 months ago

Hello @desrosj,

The function setcookie() args: http://php.net/setcookie

setcookie ( string $name [, string $value = "" [, int $expires = 0 [, string $path = "" [, string $domain = "" [, bool $secure = FALSE [, bool $httponly = FALSE ]]]]]] ) : bool

The 5th parameter type is string, but the default constant COOKIE_DOMAIN type is boolean.

<?php

// So when I code below in my theme/plugin:
declare(strict_types = 1);

\setcookie(
    'name',
    'value',
    \time() + \YEAR_IN_SECONDS,
    \COOKIEPATH,
    \COOKIE_DOMAIN // This is not string
//    \is_bool(\COOKIE_DOMAIN) ? \COOKIE_DOMAIN : '' // I need to code on this way XD
);

So I think the default value shall be define( 'COOKIE_DOMAIN', '' );.

Note: See TracTickets for help on using tickets.