mdref.json config
[mdref/mdref-http] / http / Message / setHeaders.md
1 # http\Message http\Message::setHeaders(array $headers = NULL)
2
3 Set the message headers.
4 See http\Message::getHeaders() and http\Message::addHeaders().
5
6 > ***NOTE:***
7 > Prior to v2.5.6/v3.1.0 headers with the same name were merged into a single
8 > header with values concatenated by comma.
9
10 ## Params:
11
12 * array $headers = NULL
13 The message's headers.
14
15 ## Returns:
16
17 * http\Message, null.
18
19 ## Example:
20
21 <?php
22 $msg = new http\Message;
23
24 $msg->setHeaders([
25 "Content-Type" => "text/plain",
26 "Content-Encoding" => "gzip",
27 "Content-Location" => "/foo/bar"
28 ]);
29 var_dump($msg->getHeaders());
30
31 $msg->setHeaders(null);
32 var_dump($msg->getHeaders());
33 ?>
34
35 Yields:
36
37 array(3) {
38 ["Content-Type"]=>
39 string(10) "text/plain"
40 ["Content-Encoding"]=>
41 string(4) "gzip"
42 ["Content-Location"]=>
43 string(8) "/foo/bar"
44 }
45 array(0) {
46 }
47
48 ## Changelog:
49
50 0. 2.5.6, 3.1.0
51 * Multiple headers with the same name are kept separate instead of merged together.