php8.5
Home/ Manual/ yaf / yaf_response_abstract/ Yaf_Response_Abstract::getHeader

Yaf_Response_Abstract::getHeader

PHP function Edit on GitHub ✎

(Yaf >=1.0.0)

Retrieve an HTTP response header

Description

Yaf_Response_Abstract::getHeader([string $name]): string|array|null

Retrieve an HTTP response header.

Note

This method is only fully implemented in the Yaf_Response_Http subclass. In the abstract class it is a stub.

Parameters

name

The header name. If omitted, all headers are returned as an array.

Return Values

The header value as a string, or an array of all headers when the name is omitted. Returns null if the requested header is not set.

Examples

Yaf_Response_Abstract::getHeader example

php
<?php
class IndexController extends Yaf_Controller_Abstract
{
    public function indexAction()
    {
        $response = $this->getResponse();
        $response->setHeader("Content-Type", "application/json");

        var_dump($response->getHeader("Content-Type"));
        var_dump($response->getHeader()); // all headers
        var_dump($response->getHeader("X-Missing"));
    }
}
?>

The above example will output something similar to:

output
string(16) "application/json"
array(1) {
  ["Content-Type"]=>
  string(16) "application/json"
}
NULL

See Also

  • Yaf_Response_Abstract::setHeader
  • Yaf_Response_Abstract::clearHeaders
  • Yaf_Response_Abstract::setAllHeaders

Source: reference/yaf/yaf_response_abstract/getheader.xml · from the official PHP manual (php/doc-en)