# Response-\>type vs response-\>withType

**URL:** <https://discourse.cakephp.org/t/response-type-vs-response-withtype/3955>\
**Category:** Need Help\
**Created:** [February 23, 2018, 5:38am UTC](https://discourse.cakephp.org/t/response-type-vs-response-withtype/3955 "2018-02-23T05:38:23Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jerome.oneil](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/jerome.oneil/32/376_2.png) [@jerome.oneil](https://discourse.cakephp.org/u/jerome.oneil)\
**Post date:** [February 23, 2018, 5:38am UTC](https://discourse.cakephp.org/t/response-type-vs-response-withtype/3955/1 "2018-02-23T05:38:23Z")

</div>

When setting a response content-type header, what is the difference between

`$response->type('content/joy');`

and

`$response->withType('content/joy');`

Other than the fact that the former seems to work and the later does not?

I’m using CakePHP 3.5.x, and the only way I can control content type for responses is to use the first method. The second method does nothing.

---

<div class="post-metadata">

**Author:** ![raul338](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/raul338/32/69_2.png) [@raul338](https://discourse.cakephp.org/u/raul338)\
**Post date:** [February 23, 2018, 2:23pm UTC](https://discourse.cakephp.org/t/response-type-vs-response-withtype/3955/2 "2018-02-23T14:23:40Z")

</div>

The first one is keeped for backwards compatibility reasons, it will be deprecated in 3.6 and removed in 4.0

The second one is part of the [PSR-7](https://www.php-fig.org/psr/psr-7/) interface, it was created to be inmutable. You should use it like this

```php
$this->response = $response->withType('content/joy');

```

---

<div class="post-metadata">

**Author:** ![jerome.oneil](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/jerome.oneil/32/376_2.png) [@jerome.oneil](https://discourse.cakephp.org/u/jerome.oneil)\
**Post date:** [February 23, 2018, 8:22pm UTC](https://discourse.cakephp.org/t/response-type-vs-response-withtype/3955/3 "2018-02-23T20:22:45Z")

</div>

Why in Gawd’s name would they make the response object immutable? That would make sense for the request, but the entire point of the framework is that I have control over the response.

That should be revisited, as it’s a really bad idea.

---

<div class="post-metadata">

**Author:** ![raul338](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/raul338/32/69_2.png) [@raul338](https://discourse.cakephp.org/u/raul338)\
**Post date:** [February 24, 2018, 1:35am UTC](https://discourse.cakephp.org/t/response-type-vs-response-withtype/3955/4 "2018-02-24T01:35:43Z")

</div>

Its part of the [PHP-FIG](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-7-http-message.md) and not CakePHP alone.  
This will allow the PHP ecosystem to grow in packages that can coexists without building bridges, every modern framework/library will use the inmutable request/response
