Cookie::__construct( string $name, string $value, array|WpOrgRequestsUtilityCaseInsensitiveDictionary $attributes = array(), array $flags = array(), int|null $reference_time = null )
Create a new cookie object
Parameters
- $name
-
(Required) The name of the cookie.
- $value
-
(Required) The value for the cookie.
- $attributes
-
(Optional) Associative array of attribute data
Default value: array()
- $flags
-
(Optional) The flags for the cookie.<br> Valid keys are
'creation'
,'last-access'
,'persistent'
and'host-only'
.Default value: array()
- $reference_time
-
(Optional) Reference time for relative calculations.
Default value: null
Source
File: wp-includes/Requests/src/Cookie.php
public function __construct($name, $value, $attributes = [], $flags = [], $reference_time = null) {
if (is_string($name) === false) {
throw InvalidArgument::create(1, '$name', 'string', gettype($name));
}
if (is_string($value) === false) {
throw InvalidArgument::create(2, '$value', 'string', gettype($value));
}
if (InputValidator::has_array_access($attributes) === false || InputValidator::is_iterable($attributes) === false) {
throw InvalidArgument::create(3, '$attributes', 'array|ArrayAccess&Traversable', gettype($attributes));
}
if (is_array($flags) === false) {
throw InvalidArgument::create(4, '$flags', 'array', gettype($flags));
}
if ($reference_time !== null && is_int($reference_time) === false) {
throw InvalidArgument::create(5, '$reference_time', 'integer|null', gettype($reference_time));
}
$this->name = $name;
$this->value = $value;
$this->attributes = $attributes;
$default_flags = [
'creation' => time(),
'last-access' => time(),
'persistent' => false,
'host-only' => true,
];
$this->flags = array_merge($default_flags, $flags);
$this->reference_time = time();
if ($reference_time !== null) {
$this->reference_time = $reference_time;
}
$this->normalize();
}