cookie
[mdref/mdref-http] / http / Cookie / __construct.md
1 # void http\Cookie::__construct([mixed $cookies = NULL[, int $flags = 0[, array $allowed_extras = NULL]]])
2
3 Create a new cookie list.
4
5 ## Params:
6
7 * Optional mixed $cookies = NULL
8 The string or list of cookies to parse or set.
9 * Optional int $flags = 0
10 Parse flags. See http\Cookie::PARSE_* constants.
11 * Optional array $allowed_extras = NULL
12 List of extra attribute names to recognize.
13
14 ## Throws:
15
16 * http\Exception.
17
18 ## Example:
19
20 <?php
21 $cookie = new http\Cookie("c1=v1; c2=v2; extra=foo; ".
22 "expires=Thu, Nov 7 2013 10:00:00 GMT; path=/a/b/c",
23 0, ["extra"]);
24 var_dump([
25 "cookies" => $cookie->getCookies(),
26 "extras" => $cookie->getExtras(),
27 "expires" => $cookie->getExpires(),
28 "max-age" => $cookie->getMaxAge(),
29 "domain" => $cookie->getDomain(),
30 "path" => $cookie->getPath(),
31 "flags" => $cookie->getFlags(),
32 "string" => (string) $cookie
33 ]);
34 ?>
35
36 Yields:
37
38 array(8) {
39 ["cookies"]=>
40 array(2) {
41 ["c1"]=>
42 string(2) "v1"
43 ["c2"]=>
44 string(2) "v2"
45 }
46 ["extras"]=>
47 array(1) {
48 ["extra"]=>
49 string(3) "foo"
50 }
51 ["expires"]=>
52 int(1383818400)
53 ["max-age"]=>
54 int(-1)
55 ["domain"]=>
56 NULL
57 ["path"]=>
58 string(6) "/a/b/c"
59 ["flags"]=>
60 int(0)
61 ["string"]=>
62 string(77) "c1=v1; c2=v2; path=/a/b/c; expires=Thu, 07 Nov 2013 10:00:00 GMT; extra=foo; "
63 }