# \`$this-\>request\` vs \`$this-\>getRequest()\`

**URL:** https://discourse.cakephp.org/t/this-request-vs-this-getrequest/8348
**Category:** Need Help
**Created:** [September 7, 2020, 11:29am UTC](https://discourse.cakephp.org/t/this-request-vs-this-getrequest/8348 "2020-09-07T11:29:51Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![alex](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/alex/32/2375_2.png) [@alex](https://discourse.cakephp.org/u/alex)
#### Post date: [September 7, 2020, 11:29am UTC](https://discourse.cakephp.org/t/this-request-vs-this-getrequest/8348/1 "2020-09-07T11:29:51Z")

</div>

Hi everyone,

I very often see people using `$this->request`, even on the (relatively) recent Stackoverflow posts (e.g. [here](https://stackoverflow.com/questions/45031954/cakephp-3-this-request-getdata-when-reading-post-arrays), [here](https://stackoverflow.com/questions/54825312/cakephp-3-correct-way-to-modify-request-data-in-a-controller)).

However, seeing where things have been going with the mass deprecation because of the get/set prefix addition since [3.4](https://api.cakephp.org/3.4/annotation-group-deprecated.html) and [3.6](https://api.cakephp.org/3.6/annotation-group-deprecated.html), do I feel right that one should move to `$this->getRequest()` instead of `$this->request` as well?

The reason I’m asking is because I called `$this->request->getRequestTarget()` on my 3.8 and it didn’t show me any deprecation warnings in the debug panel (while I thought it would).

---

<div class="post-metadata">

### Author: ![Zuluru](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/zuluru/32/1230_2.png) [@Zuluru](https://discourse.cakephp.org/u/Zuluru)
#### Post date: [September 7, 2020, 4:29pm UTC](https://discourse.cakephp.org/t/this-request-vs-this-getrequest/8348/2 "2020-09-07T16:29:09Z")

</div>

Note that both of the deprecation notices you link to specify that the `request` property of _components_ is deprecated, not the _controller_ property, which is what the SO articles are referencing.

---

<div class="post-metadata">

### Author: ![curlyjason](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/curlyjason/32/1940_2.png) [@curlyjason](https://discourse.cakephp.org/u/curlyjason)
#### Post date: [September 15, 2020, 5:14pm UTC](https://discourse.cakephp.org/t/this-request-vs-this-getrequest/8348/3 "2020-09-15T17:14:21Z")

</div>

The question that’s interesting to me, here, is if $this-\>request is to be deprecated. I’m working on a new 4.0 solution, and, honestly, using both $this-\>request and $this-\>getRequest().  
What is the community preference?

---

<div class="post-metadata">

### Author: ![Hache\_raw](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/hache_raw/32/1569_2.png) [@Hache\_raw](https://discourse.cakephp.org/u/Hache_raw)
#### Post date: [February 16, 2021, 7:57pm UTC](https://discourse.cakephp.org/t/this-request-vs-this-getrequest/8348/4 "2021-02-16T19:57:10Z")

</div>

I was about to ask the same question.

Is `$this->getRequest()` preferable to `$this->request` ?

I think the answer is yes because in the past there were deprecations in favour of get/set prefixes… but I can’t find the reason why this is not deprecated/removed in 4.x or if it will ever be

**Any new thoughts about this?**

---

<div class="post-metadata">

### Author: ![shadowx.jb](https://avatars.discourse-cdn.com/v4/letter/s/a88e4f/32.png) [@shadowx.jb](https://discourse.cakephp.org/u/shadowx.jb)
#### Post date: [October 31, 2025, 4:34pm UTC](https://discourse.cakephp.org/t/this-request-vs-this-getrequest/8348/5 "2025-10-31T16:34:34Z")

</div>

I would also be interested in what is better to use?

---

<div class="post-metadata">

### Author: ![dereuromark](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/dereuromark/32/37_2.png) [@dereuromark](https://discourse.cakephp.org/u/dereuromark)
#### Post date: [November 2, 2025, 11:59pm UTC](https://discourse.cakephp.org/t/this-request-vs-this-getrequest/8348/6 "2025-11-02T23:59:51Z")

</div>

It is simple:

If you are IN the same object that officially has it declared (controller, view), use the (protected) property (since thats the definition of scope for protected access).

If you are trying to use it from anywhere else outside, you need to use the public API method; e.g.

- components - when trying to access it from inside components via controller then
- helpers - via view

etc
