# New globals for PUT and DELETE

- Thread: https://externals.io/message/77972
- Original archive: https://news-web.php.net/php.internals/77972
- Started by Kris Craig on 2014-10-14T12:47:22+00:00
- Messages: 94
- Page 1 of 4: messages 1 to 25 (25 per page, add `?page=N` to the URL)
- Next page: https://externals.io/message/77972.md?page=2
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · RFCs at https://externals.io/rfc.md · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #77972 — Kris Craig — 2014-10-14T12:47:22+00:00

URL: https://externals.io/message/77972#77972

Hey guys,

Does anybody know why we have $_GET and $_POST, but not $_PUT and
$_DELETE?  As far as I can tell, the only way to get these out currently is
to parse their values by reading the incoming stream directly.

Is there a reason why we don't want this or is it just that nobody has
actually written it yet?

--Kris

---

## #77973 — Peter Lind — 2014-10-14T12:51:36+00:00

URL: https://externals.io/message/77972#77973 · In reply to: #77972

Last time it stranded here:
https://www.mail-archive.com/internals@lists.php.net/msg67294.html

And I believe it's been up a number of times before that.



> Hey guys,
>
> Does anybody know why we have $_GET and $_POST, but not $_PUT and
> $_DELETE?  As far as I can tell, the only way to get these out currently is
> to parse their values by reading the incoming stream directly.
>
> Is there a reason why we don't want this or is it just that nobody has
> actually written it yet?
>
> --Kris
>



-- 
<hype>
WWW: plphp.dk / plind.dk
CV: careers.stackoverflow.com/peterlind
LinkedIn: plind
Twitter: kafe15
</hype

---

## #77974 — Andrea Faulds — 2014-10-14T12:54:55+00:00

URL: https://externals.io/message/77972#77974 · In reply to: #77972

> Hey guys,
> 
> Does anybody know why we have $_GET and $_POST, but not $_PUT and
> $_DELETE?  As far as I can tell, the only way to get these out currently is
> to parse their values by reading the incoming stream directly.
> 
> Is there a reason why we don't want this or is it just that nobody has
> actually written it yet?

$_GET and $_POST are really misnomers. $_GET is query string parameters, $_POST is request body data.

We should just put the request bodies for all requests, not just POST, into $_POST.

--
Andrea Faulds
http://ajf.me/

---

## #77976 — Kris Craig — 2014-10-14T13:09:18+00:00

URL: https://externals.io/message/77972#77976 · In reply to: #77974

>
> 
>
> > […]
> is
> > […]
>
> $_GET and $_POST are really misnomers. $_GET is query string parameters,
> $_POST is request body data.
>
> We should just put the request bodies for all requests, not just POST,
> into $_POST.
>
> --
> Andrea Faulds
> http://ajf.me/
>
>
The problem with that approach though is that it would not be RESTful.  I'm
developing a REST API (with the goal of 100% REST compliance) and having
PUT/DELETE variables mixed in with $_POST would not only be
counter-intuitive, but it would just present a new roadblock.
Incorporating GET in there, as well, would make things even worse.

Basically, if we have $_GET and $_POST, then we should also have $_PUT and
$_DELETE.  Either that, or they should all be tossed.  There's no reason
why $_PUT and $_DELETE should not also exist.

--Kris

---

## #77977 — Ben Ramsey — 2014-10-14T13:09:41+00:00

URL: https://externals.io/message/77972#77977 · In reply to: #77972

> Hey guys,
> 
> Does anybody know why we have $_GET and $_POST, but not $_PUT and
> $_DELETE?  As far as I can tell, the only way to get these out currently is
> to parse their values by reading the incoming stream directly.
> 
> Is there a reason why we don't want this or is it just that nobody has
> actually written it yet?
> 
> —Kris

This is due to the history of HTML forms sending POST requests with the Content-Type application/x-www-form-urlencoded. That is, all the fields are key/value pairs and may be easily converted into a PHP array. If you use POST with application/json, nothing appears in $_POST, for example.

In practice, we could support $_PUT and $_DELETE for requests that use application/x-www-form-urlencoded, but most folks implementing PUT and DELETE do not use application/x-www-form-urlencoded for these requests.

I would venture to say that most people implementing PUT requests accept application/json and most DELETE requests have no body at all. So, $_PUT and $_DELETE superglobals wouldn’t make sense.

-Ben

---

## #77979 — Kris Craig — 2014-10-14T13:17:16+00:00

URL: https://externals.io/message/77972#77979 · In reply to: #77977

> 
>
> > […]
> is
> > […]
>
> This is due to the history of HTML forms sending POST requests with the
> Content-Type application/x-www-form-urlencoded. That is, all the fields are
> key/value pairs and may be easily converted into a PHP array. If you use
> POST with application/json, nothing appears in $_POST, for example.
>
> In practice, we could support $_PUT and $_DELETE for requests that use
> application/x-www-form-urlencoded, but most folks implementing PUT and
> DELETE do not use application/x-www-form-urlencoded for these requests.
>
> I would venture to say that most people implementing PUT requests accept
> application/json and most DELETE requests have no body at all. So, $_PUT
> and $_DELETE superglobals wouldn’t make sense.
>
> -Ben
>
>
I'm not following your logic, Ben.  Just because there are a lot of people
out there who don't understand REST, doesn't mean we shouldn't add support
for the other methods.  Besides, if anyone wants to develop a truly RESTful
API in PHP-- which a lot of devs are doing every day-- not giving them
$_PUT and $_DELETE is what wouldn't make any sense.  I'm writing an API now
and the lack of those two globals has proven to be a real pain in the ass.
The Content-Type argument really isn't an issue since the API developer
should be setting the right headers for the request method, anyway.

I don't see any gain in not making those globals available.  All it does is
present both inconvenience and inconsistency for any REST-based project.

--Kris

---

## #77980 — Rowan Collins — 2014-10-14T13:20:08+00:00

URL: https://externals.io/message/77972#77980 · In reply to: #77976

Kris Craig wrote (on 14/10/2014):
> The problem with that approach though is that it would not be RESTful.  I'm
> developing a REST API (with the goal of 100% REST compliance) and having
> PUT/DELETE variables mixed in with $_POST would not only be
> counter-intuitive, but it would just present a new roadblock.

This makes no sense; there is no such thing as "PUT/DELETE variables" in 
HTTP, any more than there is such things as "POST variables".

Just imagine that the variables are called $_QUERY_STRING and 
$_REQUEST_BODY. They should be completely orthogonal to the request method.

Note that this is already true to an extent - you can access the query 
string through $_GET on a POST request, and $_POST will exist as an 
empty array.

---

## #77981 — Ben Ramsey — 2014-10-14T13:20:29+00:00

URL: https://externals.io/message/77972#77981 · In reply to: #77976

> 
> 
> > […]
> The problem with that approach though is that it would not be RESTful.  I'm
> developing a REST API (with the goal of 100% REST compliance) and having
> PUT/DELETE variables mixed in with $_POST would not only be
> counter-intuitive, but it would just present a new roadblock.
> Incorporating GET in there, as well, would make things even worse.
> 
> Basically, if we have $_GET and $_POST, then we should also have $_PUT and
> $_DELETE.  Either that, or they should all be tossed.  There's no reason
> why $_PUT and $_DELETE should not also exist.

Putting everything into $_POST isn’t a question of being RESTful or not. REST in a
Web application happens at the HTTP protocol level and not the PHP level.

That said, it would be confusing to place the request body for all requests into $_POST.
You also have to consider PATCH and the potential body for other HTTP methods. The
easiest way to get the body of any HTTP request is to use the input stream:

$requestBody = file_get_contents('php://input');

I suppose we could make a super global that returns that for us, but it’s just as easy to
use the above. Additionally, you might not want to put the full body of the request into
memory like that. You might rather read the stream only a few bytes at a time.

-Ben

---

## #77983 — Andrey Andreev — 2014-10-14T13:23:09+00:00

URL: https://externals.io/message/77972#77983 · In reply to: #77976

> 
>
> > […]
> The problem with that approach though is that it would not be RESTful.  I'm
> developing a REST API (with the goal of 100% REST compliance) and having
> PUT/DELETE variables mixed in with $_POST would not only be
> counter-intuitive, but it would just present a new roadblock.
> Incorporating GET in there, as well, would make things even worse.
>
> Basically, if we have $_GET and $_POST, then we should also have $_PUT and
> $_DELETE.  Either that, or they should all be tossed.  There's no reason
> why $_PUT and $_DELETE should not also exist.
>
> --Kris

This has nothing to do with REST.

$_GET doesn't even relate to GET requests, it's just query parameters.
Query parameters exist in all types of requests because they are part
of the URI.
$_POST (even if only parsed for POST requests) also represents just
the request body parsed from a very specific format.

There's no reason to have $_PUT, $_DELETE, etc. because they would
represent the same thing - php://input parsed from
application/x-www-form-urlencoded.

That being said, from a purely semantic prospective, both $_GET and
$_POST should be tossed - yes. In reality, you can't do that because
virtually all PHP applications use them. But this is no reason to add
even more global vars with such misleading ... meanings.

What would be nice is to be able to register userland parsers into a
"request body parser" of some kind, so that you can have automatic
parsing depending on the Content-Type header.

Cheers,
Andrey.

---

## #77984 — Rowan Collins — 2014-10-14T13:24:04+00:00

URL: https://externals.io/message/77972#77984 · In reply to: #77979

Kris Craig wrote (on 14/10/2014):
> The Content-Type argument really isn't an issue since the API developer
> should be setting the right headers for the request method, anyway.

I think the point is that there's currently no mechanism for data from 
anything other than application/x-www-form-urlencoded and 
multipart/form-data to end up in $_POST anyway.

There was a discussion of that a while back, and I think there's talk on 
PHP-FIG about how standardising HTTP interfaces. It comes down to 
needing some flexibility over /how/ different content types are parsed, 
which makes a function-call based API make more sense than one that 
silently slurps the data on every page load.

---

## #77985 — Andrea Faulds — 2014-10-14T13:25:45+00:00

URL: https://externals.io/message/77972#77985 · In reply to: #77983

> That being said, from a purely semantic prospective, both $_GET and
> $_POST should be tossed - yes. In reality, you can't do that because
> virtually all PHP applications use them. But this is no reason to add
> even more global vars with such misleading ... meanings.

Let’s add $_REQUEST_BODY and $_QUERY_STRING and make them aliases of $_GET and $_POST then. Because they’re aliases (by-reference superglobals), there’s no additional memory consumption, but we finally have saner names.
--
Andrea Faulds
http://ajf.me/

---

## #77986 — Kristopher — 2014-10-14T13:27:51+00:00

URL: https://externals.io/message/77972#77986 · In reply to: #77985

>
> Let’s add $_REQUEST_BODY and $_QUERY_STRING and make them aliases of $_GET
> and $_POST then. Because they’re aliases (by-reference superglobals),
> there’s no additional memory consumption, but we finally have saner names.
>
>
$_HTTP_REQUEST_BODY and $_HTTP_QUERY_STRING for nostalgia's sake.

---

## #77987 — Ben Ramsey — 2014-10-14T13:29:44+00:00

URL: https://externals.io/message/77972#77987 · In reply to: #77985

> Let’s add $_REQUEST_BODY and $_QUERY_STRING and make them aliases of $_GET and $_POST then. Because they’re aliases (by-reference superglobals), there’s no additional memory consumption, but we finally have saner names.

But they are neither the request body nor the query string at that point. They are arrays that represent them. I agree that $_GET and $_POST are left-overs from a bygone day. Introducing aliases adds more confusion, IMHO.

-Ben

---

## #77988 — Andrea Faulds — 2014-10-14T13:29:57+00:00

URL: https://externals.io/message/77972#77988 · In reply to: #77986

> $_HTTP_REQUEST_BODY and $_HTTP_QUERY_STRING for nostalgia's sake.

Ew, non-superglobals.

But $_REQUEST_BODY and $_QUERY_STRING are a bit lengthy. Perhaps $_QUERY (for $_GET) and $_BODY (for $_POST)? Then the variable set finally makes sense, but isn’t too long:

* $_QUERY   - query string parameters
* $_BODY    - request body parameters
* $_REQUEST - query string and request body parameters

Makes more sense than $_GET and $_POST.

Any objections?

--
Andrea Faulds
http://ajf.me/

---

## #77989 — Chris Wright — 2014-10-14T13:30:31+00:00

URL: https://externals.io/message/77972#77989 · In reply to: #77985

>
> 
>
> > […]
>
> Let’s add $_REQUEST_BODY and $_QUERY_STRING and make them aliases of $_GET and $_POST then. Because they’re aliases (by-reference superglobals), there’s no additional memory consumption, but we finally have saner names.

$_BODY and $_QUERY would be better, IMHO. The brevity would be
consistent both historically and with other existing superglobal
names, and at least with $_QUERY_STRING the data is not a string.

I suggested this a while ago, people didn't like the idea, and I'm not
sure I do any more, either. We'd do much better focusing on creating a
standard native request *object* which provides clean access to this
data, and other things that are clumsy at the moment, such as request
headers.

---

## #77990 — Ben Ramsey — 2014-10-14T13:33:46+00:00

URL: https://externals.io/message/77972#77990 · In reply to: #77989

> I suggested this a while ago, people didn't like the idea, and I'm not
> sure I do any more, either. We'd do much better focusing on creating a
> standard native request *object* which provides clean access to this
> data, and other things that are clumsy at the moment, such as request
> headers.


Agreed, and it seems that’s what PHP-FIG is working on for user land:
https://github.com/php-fig/fig-standards/blob/master/proposed/http-message.md

-Ben

---

## #77992 — Mike Dugan — 2014-10-14T13:41:18+00:00

URL: https://externals.io/message/77972#77992 · In reply to: #77988

On 14 Oct 2014, at 14:27, Kristopher <kristopherwilson@gmail.com> wrote: 

> $_HTTP_REQUEST_BODY and $_HTTP_QUERY_STRING for nostalgia's sake. 

Ew, non-superglobals. 

But $_REQUEST_BODY and $_QUERY_STRING are a bit lengthy. Perhaps $_QUERY (for $_GET) and $_BODY (for $_POST)? Then the variable set finally makes sense, but isn’t too long: 

* $_QUERY - query string parameters 
* $_BODY - request body parameters 
* $_REQUEST - query string and request body parameters 

Makes more sense than $_GET and $_POST. 

Any objections? 

-- 
Andrea Faulds 
http://ajf.me/ 


+1 for this. This would hopefully also eliminate the confusion for new developers (or not-so-new developers) who don’t quite understand that $_GET and $_POST don’t strictly relate to their HTTP verbs of the same name.

--

Mike Dugan

mike@mjdugan.com






--

---

## #77993 — Kris Craig — 2014-10-14T13:42:09+00:00

URL: https://externals.io/message/77972#77993 · In reply to: #77985

>
> 
>
> > […]
>
> Let’s add $_REQUEST_BODY and $_QUERY_STRING and make them aliases of $_GET
> and $_POST then. Because they’re aliases (by-reference superglobals),
> there’s no additional memory consumption, but we finally have saner names.
> --
> Andrea Faulds
> http://ajf.me/
>
>
I don't think that would be a good idea, either.  They require more typing
and it'd probably be a lot easier for devs to remember which one means GET
and which one means POST.

The fact that $_PUT and $_DELETE aren't necessary because we can use other
approaches to get that data is irrelevant.  Having globals for two REST
methods but not the other two is very counter-intuitive from a dev
standpoint.  We just recently discussed how PHP tends to have duplicate
ways of doing something in order to make it as easy as possible.  I believe
this is one of those times.  It would make it a lot easier for devs,
particularly the ones less experienced with REST, to create APIs that
actually use the correct methods without running into the confusion over
why there's a $_GET and a $_POST but not a $_PUT or a $_DELETE.

PHP is supposed to be KISS, right?  Well, the current reliance on
php://input for two methods but not the other two invites confusion.  That
makes it less-than simple, I believe.

Removing or renaming $_GET and $_POST would also create confusion and
almost certainly cause widespread BC breakage on a pretty massive scale.
And there's really no gain to offset that.  So that just leaves us with
either continuing to have two REST methods but not the others or add a
$_PUT and a $_DELETE, even if they just alias to php://input again.

--Kris

---

## #77994 — Kris Craig — 2014-10-14T13:46:41+00:00

URL: https://externals.io/message/77972#77994 · In reply to: #77992

>
> 
>
>
> 
>
> > […]
>
> Ew, non-superglobals.
>
> But $_REQUEST_BODY and $_QUERY_STRING are a bit lengthy. Perhaps $_QUERY
> (for $_GET) and $_BODY (for $_POST)? Then the variable set finally makes
> sense, but isn’t too long:
>
> * $_QUERY - query string parameters
> * $_BODY - request body parameters
> * $_REQUEST - query string and request body parameters
>
> Makes more sense than $_GET and $_POST.
>
> Any objections?
>
> --
> Andrea Faulds
> http://ajf.me/
>
>
> +1 for this. This would hopefully also eliminate the confusion for new
> developers (or not-so-new developers) who don’t quite understand that $_GET
> and $_POST don’t strictly relate to their HTTP verbs of the same name.
>
> --
>
> Mike Dugan
>
> mike@mjdugan.com
>

That could work, though the BC breakage will be extreme.  I'm not sure if
that's worth it even in a major version increment.  On the other hand,
making $_PUT and $_DELETE available wouldn't break anything and wouldn't
require re-training for devs.

--Kris

---

## #77995 — Mike Dugan — 2014-10-14T13:47:01+00:00

URL: https://externals.io/message/77972#77995 · In reply to: #77993

-- 
Mike Dugan
mike@mjdugan.com



On Tue, Oct 14, 2014 at 6:25 AM, Andrea Faulds <ajf@ajf.me> wrote: 

> 
> On 14 Oct 2014, at 14:23, Andrey Andreev <narf@devilix.net> wrote: 
> 
> > […]
> 
> Let’s add $_REQUEST_BODY and $_QUERY_STRING and make them aliases of $_GET 
> and $_POST then. Because they’re aliases (by-reference superglobals), 
> there’s no additional memory consumption, but we finally have saner names. 
> -- 
> Andrea Faulds 
> http://ajf.me/ 
> 
> 

Removing or renaming $_GET and $_POST would also create confusion and 
almost certainly cause widespread BC breakage on a pretty massive scale. 
And there's really no gain to offset that. So that just leaves us with 
either continuing to have two REST methods but not the others or add a 
$_PUT and a $_DELETE, even if they just alias to php://input again. 


--Kris 
How are these RESTful methods? $_GET accepts query strings, that’s not part of the spec for RESTful GET requests unless I missed something. I also don’t see the worldwide breakage and confusion that would be caused - no one is proposing to drop $_GET and $_POST but rather to create more semantic aliases for them.

—

Mike Dugan

mike@mjdugan.com

---

## #77996 — Andrea Faulds — 2014-10-14T13:47:22+00:00

URL: https://externals.io/message/77972#77996 · In reply to: #77993

> I don't think that would be a good idea, either.  They require more typing
> and it'd probably be a lot easier for devs to remember which one means GET
> and which one means POST.

I’ve already proposed the shorter $_QUERY and $_BODY.

> PHP is supposed to be KISS, right?  Well, the current reliance on
> php://input for two methods but not the other two invites confusion.  That
> makes it less-than simple, I believe.
> 
> Removing or renaming $_GET and $_POST would also create confusion and
> almost certainly cause widespread BC breakage on a pretty massive scale.

I never said anything about removing $_GET or $_POST. I suggested adding saner aliases.

> And there's really no gain to offset that.  So that just leaves us with
> either continuing to have two REST methods but not the others or add a
> $_PUT and a $_DELETE, even if they just alias to php://input again.

Adding $_PUT and $_DELETE is silly. We already have a nonsensical system where $_GET isn’t about GET, but about query string parameters, and $_POST isn’t about POST, but the request body. We should create sane aliases ($_QUERY and $_BODY) and extend $_POST/$_BODY to support request bodies from any method.

This would make things actually simpler, and less confusing, as we stop pretending $_GET is about GET and $_POST is about POST. By using $_QUERY, it’s clear it’s about query string parameters, which any method can have. Similarly, by using $_BODY, it’s clear it’s about request body parameters, which any method can also have.

Sure, all existing code uses $_GET and $_POST and they won’t go away any time soon. But we would have saner names that people writing new code can use.

--
Andrea Faulds
http://ajf.me/

---

## #77997 — Chris Wright — 2014-10-14T13:50:01+00:00

URL: https://externals.io/message/77972#77997 · In reply to: #77994

> 
>
> > […]
>
> That could work, though the BC breakage will be extreme.  I'm not sure if
> that's worth it even in a major version increment.  On the other hand,
> making $_PUT and $_DELETE available wouldn't break anything and wouldn't
> require re-training for devs.

...but is also the wrong solution. It's not scalable, and the only
sensible way to implement them would be as aliases of $_POST, because
they would contain the same data. How does this fundamentally differ
from $_BODY (or whatever)?

---

## #77999 — Alain Williams — 2014-10-14T13:50:43+00:00

URL: https://externals.io/message/77972#77999 · In reply to: #77974

> 
> 
> 
> > […]
> 
> $_GET and $_POST are really misnomers. $_GET is query string parameters, $_POST is request body data.
> 
> We should just put the request bodies for all requests, not just POST, into $_POST.

Unless I have misunderstood what you are saying ...

as a developer I do want to know the difference between fields in a POST form
and query items on the URL. I will sometimes use them together, eg:

    <form action="?context=something" method="post" >
    ...

and specifically check $_GET['context'] - there might be a $_POST['context'] but
that is treated completely differently.

-- 
Alain Williams
Linux/GNU Consultant - Mail systems, Web sites, Networking, Programmer, IT Lecturer.
+44 (0) 787 668 0256  http://www.phcomp.co.uk/
Parliament Hill Computers Ltd. Registration Information: http://www.phcomp.co.uk/contact.php
#include <std_disclaimer.h

---

## #78000 — Kris Craig — 2014-10-14T13:52:08+00:00

URL: https://externals.io/message/77972#78000 · In reply to: #77996

>
> 
>
> > […]
> typing
> > […]
> GET
> > […]
>
> I’ve already proposed the shorter $_QUERY and $_BODY.
>
> > […]
> That
> > […]
>
> I never said anything about removing $_GET or $_POST. I suggested adding
> saner aliases.
>

Ok, that was my bad.  I misinterpreted.


>
> > […]
>
> Adding $_PUT and $_DELETE is silly.


No more silly than $_GET and $_POST are now.  But either way, we should try
to make things consistent.  This inconsistency only serves to invite
confusion.


> We already have a nonsensical system where $_GET isn’t about GET, but
> about query string parameters, and $_POST isn’t about POST, but the request
> body. We should create sane aliases ($_QUERY and $_BODY) and extend
> $_POST/$_BODY to support request bodies from any method.
>
> This would make things actually simpler, and less confusing, as we stop
> pretending $_GET is about GET and $_POST is about POST. By using $_QUERY,
> it’s clear it’s about query string parameters, which any method can have.
> Similarly, by using $_BODY, it’s clear it’s about request body parameters,
> which any method can also have.
>

That's a good point.  Unfortunately, $_GET and $_POST aren't going away
anytime soon.  And in the meantime, we should at least have $_PUT and
$_DELETE alias to $_POST so devs have the option of using them.


> Sure, all existing code uses $_GET and $_POST and they won’t go away any
> time soon. But we would have saner names that people writing new code can
> use.
>
> --
> Andrea Faulds
> http://ajf.me/

---

## #78001 — Chris Wright — 2014-10-14T13:53:01+00:00

URL: https://externals.io/message/77972#78001 · In reply to: #77990

>
> 
> > […]
>
>
> Agreed, and it seems that’s what PHP-FIG is working on for user land:
> https://github.com/php-fig/fig-standards/blob/master/proposed/http-message.md
>
> -Ben

PECL HTTP v2 already has this, actually:
http://devel-m6w6.rhcloud.com/mdref/http/Env/Request#

Also, I think Mike got the naming right there as well, $form is the
accurate description of what it is.

---

Next page: https://externals.io/message/77972.md?page=2
