*/ try { $request->getHeader('Some-Header-That-Isnt-Assigned'); die('Expected exception not thrown'); } catch (DomainException $e) { // Yep, it worked correctly. } /** * Most HTTP headers may appear multiple times in the same message. For this reason it makes sense * to represent all message headers as arrays. When you retrieve a header it will be returned as a * numerically-indexed array: */ $contentType = $request->getHeader('content-type'); assert(is_array($contentType)); // true assert($contentType[0] === 'text/plain'); // true /** * As a result, if you're interested in header fields for which there *should* only exist a single * value you should access them in this manner: */ if ($request->hasHeader('CONTENT-TYPE')) { $contentType = current($request->getHeader('Content-TYPE')); assert($contentType === 'text/plain'); } /** * Finally, you can clear all headers from a message in one fell swoop: */ $request->removeAllHeaders(); assert(!$request->getAllHeaders());