1--TEST--
2setcookie() array variant error tests
3--INI--
4date.timezone=UTC
5--FILE--
6<?php
7
8ob_start();
9
10// Unrecognized key and no valid keys
11try {
12    setcookie('name', 'value', ['unknown_key' => 'only']);
13} catch (\ValueError $e) {
14    echo $e->getMessage() . "\n";
15}
16// Numeric key and no valid keys
17try {
18    setcookie('name2', 'value2', [0 => 'numeric_key']);
19} catch (\ValueError $e) {
20    echo $e->getMessage() . "\n";
21}
22// Unrecognized key
23try {
24    setcookie('name3', 'value3', ['path' => '/path/', 'foo' => 'bar']);
25} catch (\ValueError $e) {
26    echo $e->getMessage() . "\n";
27}
28// Invalid path key content
29try {
30    setcookie('name', 'value', ['path' => '/;/']);
31} catch (\ValueError $e) {
32    echo $e->getMessage() . "\n";
33}
34// Invalid domain key content
35try {
36    setcookie('name', 'value', ['path' => '/path/', 'domain' => 'ba;r']);
37} catch (\ValueError $e) {
38    echo $e->getMessage() . "\n";
39}
40
41// Arguments after options array (will not be set)
42try {
43    setcookie('name4', 'value4', [], "path", "domain.tld", true, true);
44} catch (\ArgumentCountError $e) {
45    echo $e->getMessage() . "\n";
46}
47
48if (PHP_INT_SIZE == 8) {
49    try {
50        // To go above year 9999: 60 * 60 * 24 * 365 * 9999
51        setcookie('name', 'value', ['expires' => 315328464000]);
52    } catch (\ValueError $e) {
53        var_dump($e->getMessage() == 'setcookie(): "expires" option cannot have a year greater than 9999');
54    }
55} else {
56    var_dump(true);
57}
58
59var_dump(headers_list());
60--EXPECTHEADERS--
61
62--EXPECTF--
63setcookie(): option "unknown_key" is invalid
64setcookie(): option array cannot have numeric keys
65setcookie(): option "foo" is invalid
66setcookie(): "path" option cannot contain ",", ";", " ", "\t", "\r", "\n", "\013", or "\014"
67setcookie(): "domain" option cannot contain ",", ";", " ", "\t", "\r", "\n", "\013", or "\014"
68setcookie(): Expects exactly 3 arguments when argument #3 ($expires_or_options) is an array
69bool(true)
70array(1) {
71  [0]=>
72  string(%s) "X-Powered-By: PHP/%s"
73}
74