1--TEST--
2Test session_set_cookie_params() function : array parameter variation
3--INI--
4session.cookie_lifetime=0
5session.cookie_path="/"
6session.cookie_domain=""
7session.cookie_secure=0
8session.cookie_httponly=0
9session.cookie_samesite=""
10--SKIPIF--
11<?php include('skipif.inc'); ?>
12--FILE--
13<?php
14
15ob_start();
16
17echo "*** Testing session_set_cookie_params() : array parameter variation ***\n";
18
19// Invalid cases
20try {
21    session_set_cookie_params([]);
22} catch (ValueError $exception) {
23    echo $exception->getMessage() . "\n";
24}
25
26try {
27    session_set_cookie_params(["unknown_key" => true, "secure_invalid" => true]);
28} catch (ValueError $exception) {
29    echo $exception->getMessage() . "\n";
30}
31
32var_dump(ini_get("session.cookie_secure"));
33var_dump(ini_get("session.cookie_samesite"));
34var_dump(session_set_cookie_params(["secure" => true, "samesite" => "please"]));
35var_dump(ini_get("session.cookie_secure"));
36var_dump(ini_get("session.cookie_samesite"));
37
38var_dump(ini_get("session.cookie_lifetime"));
39var_dump(session_set_cookie_params(["lifetime" => 42]));
40var_dump(ini_get("session.cookie_lifetime"));
41
42var_dump(ini_get("session.cookie_path"));
43
44try {
45    session_set_cookie_params(["path" => "newpath/"], "arg after options array");
46} catch (ValueError $exception) {
47    echo $exception->getMessage() . "\n";
48}
49
50var_dump(ini_get("session.cookie_path"));
51
52echo "Done";
53ob_end_flush();
54?>
55--EXPECTF--
56*** Testing session_set_cookie_params() : array parameter variation ***
57session_set_cookie_params(): Argument #1 ($lifetime_or_options) must contain at least 1 valid key
58
59Warning: session_set_cookie_params(): Argument #1 ($lifetime_or_options) contains an unrecognized key "unknown_key" in %s on line %d
60
61Warning: session_set_cookie_params(): Argument #1 ($lifetime_or_options) contains an unrecognized key "secure_invalid" in %s on line %d
62session_set_cookie_params(): Argument #1 ($lifetime_or_options) must contain at least 1 valid key
63string(1) "0"
64string(0) ""
65bool(true)
66string(1) "1"
67string(6) "please"
68string(1) "0"
69bool(true)
70string(2) "42"
71string(1) "/"
72session_set_cookie_params(): Argument #2 ($path) must be null when argument #1 ($lifetime_or_options) is an array
73string(1) "/"
74Done
75