Skip to content

Message: withHeader Example

Terry L edited this page Jun 20, 2020 · 3 revisions
Clone this wiki locally


withHeader($name, $value)

Return an instance with the provided value replacing the specified header.

  • param string name * Case-insensitive header field name.
  • param string|array value * Header value(s)
  • return static


$message = $message->withHeader('foo', 'bar');

echo $message->getHeaderLine('foo');
// Outputs: bar

echo $message->getHeaderLine('FOO');
// Outputs: bar

$message = $message->withHeader('fOO', 'baz');
echo $message->getHeaderLine('foo');
// Outputs: baz

$message = $message->withHeader('fOO', ['bax', 'bay', 'baz']);
echo $message->getHeaderLine('foo');
// Outputs: bax, bay, baz