# HTTP supergloblas and request body/query (was: Parsing PUT data)

- Thread: https://externals.io/message/69436
- Original archive: https://news-web.php.net/php.internals/69436
- Started by Michael Wallner on 2013-10-02T06:59:15+00:00
- Messages: 27
- Page 1 of 2: messages 1 to 25 (25 per page, add `?page=N` to the URL)
- Next page: https://externals.io/message/69436.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

---

## #69436 — Michael Wallner — 2013-10-02T06:59:15+00:00

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

Since ever people are confused by _GET and _POST superglobals,
because, despite their name, they do not (really) depend on the
request method.  Therefor I propose to phase out $_GET and name it
$_QUERY and I propose to phase out $_POST and name it $_FORM (I'm not
100% confident with the latter yet, though).

Further, I propose to remove the POST method restriction for handling
request bodies and solely rely on the content type to trigger the
parser(s). (*)

There are already parsers for application/x-www-form-urlencoded and
multipart/form-data in the core.  One could think of providing an API
to add content type handlers from extensions, ext/json may be an
example, like it is hacked into pecl_http-v2.

Thoughts, objections, insults?

(*) We'd probably have to revisit all *post* INI variables, though.

-- 
Regards,
Mike

---

## #69437 — Alexey Zakhlestin — 2013-10-02T07:17:22+00:00

URL: https://externals.io/message/69436#69437 · In reply to: #69436

> Since ever people are confused by _GET and _POST superglobals,
> because, despite their name, they do not (really) depend on the
> request method.  Therefor I propose to phase out $_GET and name it
> $_QUERY and I propose to phase out $_POST and name it $_FORM (I'm not
> 100% confident with the latter yet, though).
> 
> Further, I propose to remove the POST method restriction for handling
> request bodies and solely rely on the content type to trigger the
> parser(s). (*)
> 
> There are already parsers for application/x-www-form-urlencoded and
> multipart/form-data in the core.  One could think of providing an API
> to add content type handlers from extensions, ext/json may be an
> example, like it is hacked into pecl_http-v2.
> 
> Thoughts, objections, insults?
> 
> (*) We'd probably have to revisit all *post* INI variables, though.

So, that is not one, but three proposals:

1. _GET -> _QUERY, _POST -> _FORM

  I don't think this is really necessary. Names are there historically and changing them will break a lot of stuff.
  +0 on aliasing, and soft-deprecation (via documentation) though

2. ignore request-method, trigger body-processing solely on Content-type

  +1. makes sense

3. expose body-parsers via php-level API

  +1. Hell, yes! Something like +1000, actually ;)



-- 
Alexey Zakhlestin
CTO at Grids.by/you
https://github.com/indeyets
PGP key: http://indeyets.ru/alexey.zakhlestin.pgp.asc

---

## #69438 — Michael Wallner — 2013-10-02T07:24:06+00:00

URL: https://externals.io/message/69436#69438 · In reply to: #69437

> 3. expose body-parsers via php-level API
>
>   +1. Hell, yes! Something like +1000, actually ;)

Uhmmm... I actually meant an interal API not userland :)


-- 
Regards,
Mike

---

## #69439 — Jannik Zschiesche — 2013-10-02T07:25:32+00:00

URL: https://externals.io/message/69436#69439 · In reply to: #69437

Hi,

wouldn’t $_BODY be better - since it is the request body?
$_FORM is imho not very clear, since you can send data to $_POST without using a form.


--  
Cheers
Jannik


Am Mittwoch, 2. Oktober 2013 um 09:17 schrieb Alexey Zakhlestin:

>  
> 
>  
> > […]
>  
> So, that is not one, but three proposals:
>  
> 1. _GET -> _QUERY, _POST -> _FORM
>  
> I don't think this is really necessary. Names are there historically and changing them will break a lot of stuff.
> +0 on aliasing, and soft-deprecation (via documentation) though
>  
> 2. ignore request-method, trigger body-processing solely on Content-type
>  
> +1. makes sense
>  
> 3. expose body-parsers via php-level API
>  
> +1. Hell, yes! Something like +1000, actually ;)
>  
>  
>  
> --  
> Alexey Zakhlestin
> CTO at Grids.by/you
> https://github.com/indeyets
> PGP key: http://indeyets.ru/alexey.zakhlestin.pgp.asc

---

## #69440 — Michael Wallner — 2013-10-02T07:31:50+00:00

URL: https://externals.io/message/69436#69440 · In reply to: #69439

> Hi,
>
> wouldn’t $_BODY be better - since it is the request body?
> $_FORM is imho not very clear, since you can send data to $_POST without
> using a form.

I had it, but I'm not sure $_BODY fits either, because it should be an
array. Currently only form data fits the purpose of de-serialisation
of a request body.


-- 
Regards,
Mike

---

## #69441 — Alexey Zakhlestin — 2013-10-02T08:01:33+00:00

URL: https://externals.io/message/69436#69441 · In reply to: #69438

> 
> 
> > […]
> 
> Uhmmm... I actually meant an interal API not userland :)

well, why not both? :)

string/stream in, array out


-- 
Alexey Zakhlestin
CTO at Grids.by/you
https://github.com/indeyets
PGP key: http://indeyets.ru/alexey.zakhlestin.pgp.asc

---

## #69444 — Andrea Faulds — 2013-10-02T09:58:06+00:00

URL: https://externals.io/message/69436#69444 · In reply to: #69436

> Le 2 octobre 2013 à 07:59, Michael Wallner <mike@php.net> a écrit :
>
> Since ever people are confused by _GET and _POST superglobals,
> because, despite their name, they do not (really) depend on the
> request method.  Therefor I propose to phase out $_GET and name it
> $_QUERY and I propose to phase out $_POST and name it $_FORM (I'm not
> 100% confident with the latter yet, though).
>
Backwards compatibility matters, so we should keep $_GET and $_POST but add
these as better aliases for them.
 
While we're at it, can we remove the quirk that existed due to register_globals
where periods and such are replaced with underscores? Such that for
/test.php?php.pecl=3&php_pecl=4 we'd still only have $_GET['php_pecl'] === 4 but
there would also be $_QUERY['php.pecl'] === 3 and $_QUERY['php_pecl'] === 4, if
you get where I'm coming from.
> Further, I propose to remove the POST method restriction for handling
> request bodies and solely rely on the content type to trigger the
> parser(s). (*)
+1 to this, current behaviour is nonsensical.
> There are already parsers for application/x-www-form-urlencoded and
> multipart/form-data in the core.  One could think of providing an API
> to add content type handlers from extensions, ext/json may be an
> example, like it is hacked into pecl_http-v2.
+1 Handling JSON would be pretty neat. Maybe we could even support it by default
(after all, there is the json ext), so long as getting the unparsed request body
isn't impeded by that.
--
Andrea Faulds
http://ajf.me/

---

## #69445 — Andrea Faulds — 2013-10-02T10:00:42+00:00

URL: https://externals.io/message/69436#69445

> Le 2 octobre 2013 à 10:58, Michael Wallner <mike@php.net> a écrit :
> 
> > […]
>
> That's why I said "phase out"... or is it a german anglicism?
It's not. But my understanding of "phase out" is to deprecate and eventually
remove. Considering how much code relies on $_GET and $_POST though, the most
we'll ever do is probably deprecate.
--
Andrea Faulds
http://ajf.me/

---

## #69446 — Leigh — 2013-10-02T11:12:08+00:00

URL: https://externals.io/message/69436#69446 · In reply to: #69436

> I propose to phase out $_GET and name it $_QUERY and
> I propose to phase out $_POST and name it $_FORM

I have to say I'm against this aspect of the proposal. While the names
may not be 100% accurate, _most_ people are used to their behaviour.
You certainly won't be able to remove $_GET / $_POST (implied by
"phase out") in any 5.x release, it's just too big of a BC break.

> Further, I propose to remove the POST method restriction for handling
> request bodies and solely rely on the content type to trigger the
> parser(s). (*)

This makes more sense, HTTP/1.1 spec states all methods (except TRACE)
are allowed a body. This is where it could get pretty confusing
though, since a GET is allowed a body that could populate $_POST. I
still don't think it justifies the name change though.


>
> I had it, but I'm not sure $_BODY fits either, because it should be an
> array. Currently only form data fits the purpose of de-serialisation
> of a request body.
>

Not so sure about that. I don't think there is a rule that says a body
_has_ to be in query string name=value format, or that multipart
elements _have_ to have a name=something attribute. I could quite
easily imagine PUT requests containing a textual body without an
associated field name (the URI would contain the field name).

(correct me if I'm wrong)

---

## #69447 — Alexey Zakhlestin — 2013-10-02T11:37:12+00:00

URL: https://externals.io/message/69436#69447 · In reply to: #69446

> 
> > […]
> 
> Not so sure about that. I don't think there is a rule that says a body
> _has_ to be in query string name=value format, or that multipart
> elements _have_ to have a name=something attribute. I could quite
> easily imagine PUT requests containing a textual body without an
> associated field name (the URI would contain the field name).
> 
> (correct me if I'm wrong)


In these cases, Content-type of body would different.
And proposal mentions that interpretation should happen strictly basing on the content type


-- 
Alexey Zakhlestin
CTO at Grids.by/you
https://github.com/indeyets
PGP key: http://indeyets.ru/alexey.zakhlestin.pgp.asc

---

## #69448 — Michael Wallner — 2013-10-02T12:25:47+00:00

URL: https://externals.io/message/69436#69448 · In reply to: #69445

> > […]
> It's not. But my understanding of "phase out" is to deprecate and eventually
> remove. Considering how much code relies on $_GET and $_POST though, the most
> we'll ever do is probably deprecate.

Never heard of register_long_arrays?
http://www.php.net/manual/en/ini.core.php#ini.register-long-arrays

That statement would have been applicable there, too.
Give it a long enough time frame and it becomes possible.

-- 
Regards,
Mike

---

## #69449 — Michael Wallner — 2013-10-02T12:27:06+00:00

URL: https://externals.io/message/69436#69449 · In reply to: #69446

> 
>
> > […]
>
> I have to say I'm against this aspect of the proposal. While the names
> may not be 100% accurate, _most_ people are used to their behaviour.
> You certainly won't be able to remove $_GET / $_POST (implied by
> "phase out") in any 5.x release, it's just too big of a BC break.

Right, that's why I said "phase out". Check out register_long_arrays;
those globals have been deprecated in PHP-5.0 and removed in PHP-5.4.


-- 
Regards,
Mike

---

## #69450 — Andrea Faulds — 2013-10-02T13:50:31+00:00

URL: https://externals.io/message/69436#69450 · In reply to: #69449

> Le 2 octobre 2013 à 13:27, Michael Wallner <mike@php.net> a écrit :
>
>
> 
> > […]
>
> Right, that's why I said "phase out". Check out register_long_arrays;
> those globals have been deprecated in PHP-5.0 and removed in PHP-5.4.
>
Huh, $_GET and the other superglobals were added in 4.1 to replace the
$HTTP_GET_VARS etc., and then the old way was deprecated in PHP-5.0 and removed
in PHP-5.4.
Well, perhaps $_QUERY and $_FORM can be added in 5.6, deprecated in 6.0 and
removed in 6.4, then? Who knows!
--
Andrea Faulds
http://ajf.me/

---

## #69451 — johannes@schlueters.de — 2013-10-02T14:02:54+00:00

URL: https://externals.io/message/69436#69451 · In reply to: #69450

> > […]
> Huh, $_GET and the other superglobals were added in 4.1 to replace the
> $HTTP_GET_VARS etc., and then the old way was deprecated in PHP-5.0 and removed
> in PHP-5.4.
> Well, perhaps $_QUERY and $_FORM can be added in 5.6, deprecated in 6.0 and
> removed in 6.4, then? Who knows!

Also comparing to get rid of $_* with $HTTP_*_VARS is misleading as the
HTTP_*_VARS were of limited use. register_globals was primarily used.

johannes

---

## #69453 — johannes@schlueters.de — 2013-10-02T14:10:23+00:00

URL: https://externals.io/message/69436#69453 · In reply to: #69436

> Since ever people are confused by _GET and _POST superglobals,
> because, despite their name, they do not (really) depend on the
> request method.  Therefor I propose to phase out $_GET and name it
> $_QUERY and I propose to phase out $_POST and name it $_FORM (I'm not
> 100% confident with the latter yet, though).

The later is certainly misleading. The current naming corresponds to
HTML forms.

   <form method="GET">   -> $_GET
   <form method="POST">  -> $_POST

I agree that the naming from a HTTP/REST etc. perspective is misleading,
but unless we have a clearly better naming I would resist from changing
these.

Changing these leads to an incompatibility which can not be emulated
(ignoring runkit there is no way for a user to create a custom super
global)

In case that is ignored please mind other related areas, i.e.
 `filter_input()` to make sure the resulting new language is consistent.

johannes

---

## #69454 — Nikita Popov — 2013-10-02T15:15:18+00:00

URL: https://externals.io/message/69436#69454 · In reply to: #69436

> Since ever people are confused by _GET and _POST superglobals,
> because, despite their name, they do not (really) depend on the
> request method.  Therefor I propose to phase out $_GET and name it
> $_QUERY and I propose to phase out $_POST and name it $_FORM (I'm not
> 100% confident with the latter yet, though).
>

I don't think this kind of change is worth it if you just rename two very
heavily used variables. If something in this direction is changed the
change should be more thorough (including getting away from superglobals
and representing the request state by an immutable object).


> There are already parsers for application/x-www-form-urlencoded and
> multipart/form-data in the core.  One could think of providing an API
> to add content type handlers from extensions, ext/json may be an
> example, like it is hacked into pecl_http-v2.
>

I would *strongly* recommend against adding additional body parsers that
are automatically invoked based on the content type. Adding additional
parsers creates a high security risk. E.g. exposing ext/json as it is now
would open you to a denial of service attack (if I'm not mistaken). There
has been a long history of security vulnerabilities (both DOS and RCE)
related to unnecessary or incorrect exposure of request body parsers. A
prominent recent example are the RCE vulnerabilities in Rails caused by the
exposure of YAML and JSON parsers.

Nikita

---

## #69459 — Dave — 2013-10-02T17:27:35+00:00

URL: https://externals.io/message/69436#69459 · In reply to: #69436

> Further, I propose to remove the POST method restriction for handling
request bodies and solely rely on the content type to trigger the
parser(s). (*)

+1
This would solve the with parsing multi-form data with PUT requests (and
possibly any future method types), thus enabling full REST support :)




> Since ever people are confused by _GET and _POST superglobals,
> because, despite their name, they do not (really) depend on the
> request method.  Therefor I propose to phase out $_GET and name it
> $_QUERY and I propose to phase out $_POST and name it $_FORM (I'm not
> 100% confident with the latter yet, though).
>
> Further, I propose to remove the POST method restriction for handling
> request bodies and solely rely on the content type to trigger the
> parser(s). (*)
>
> There are already parsers for application/x-www-form-urlencoded and
> multipart/form-data in the core.  One could think of providing an API
> to add content type handlers from extensions, ext/json may be an
> example, like it is hacked into pecl_http-v2.
>
> Thoughts, objections, insults?
>
> (*) We'd probably have to revisit all *post* INI variables, though.
>
> --
> Regards,
> Mike

---

## #69461 — Michael Wallner — 2013-10-02T17:59:17+00:00

URL: https://externals.io/message/69436#69461 · In reply to: #69453

> 
> > […]
>
> The later is certainly misleading. The current naming corresponds to
> HTML forms.
>
>    <form method="GET">   -> $_GET
>    <form method="POST">  -> $_POST

Heh, pretty good observation! Didn't think about that. Still not
buying. $_FORM is derived from "application/x-www-form-urlencoded"
resp. "multipart/form-data" and $_QUERY is obvious.


> I agree that the naming from a HTTP/REST etc. perspective is misleading,
> but unless we have a clearly better naming I would resist from changing
> these.

Not only for REST, but in general IMHO, e.g: <form method="POST"
action="?see=gotcha">


>
> Changing these leads to an incompatibility which can not be emulated
> (ignoring runkit there is no way for a user to create a custom super
> global)

Valid point. Though, with a long enough time frame it could be done.


> In case that is ignored please mind other related areas, i.e.
> `filter_input()` to make sure the resulting new language is consistent.

Yeah, well, there's a lot attached to that cumbersome naming, e.g. all
*_post_* INI settings etc.
I should have just resisted proposing that change, but I figured
testing for backing was cheap.

-- 
Regards,
Mike

---

## #69462 — Michael Wallner — 2013-10-02T18:02:51+00:00

URL: https://externals.io/message/69436#69462 · In reply to: #69454

> 
> > […]
>
>
> I don't think this kind of change is worth it if you just rename two very
> heavily used variables. If something in this direction is changed the change
> should be more thorough (including getting away from superglobals and
> representing the request state by an immutable object).

Well, what I want and what is in core may diverge.
May I suggest you take a look at pecl_http-v2, I'd greatly appreciate
any feedback.

>
> > […]
>
>
> I would *strongly* recommend against adding additional body parsers that are
> automatically invoked based on the content type. Adding additional parsers
> creates a high security risk. E.g. exposing ext/json as it is now would open
> you to a denial of service attack (if I'm not mistaken). There has been a
> long history of security vulnerabilities (both DOS and RCE) related to
> unnecessary or incorrect exposure of request body parsers. A prominent
> recent example are the RCE vulnerabilities in Rails caused by the exposure
> of YAML and JSON parsers.

Pointers, references, evidences?

-- 
Regards,
Mike

---

## #69464 — Nikita Popov — 2013-10-02T18:40:12+00:00

URL: https://externals.io/message/69436#69464 · In reply to: #69462

> > […]
> are
> > […]
> parsers
> > […]
> open
> > […]
> exposure
> > […]
>
> Pointers, references, evidences?
>

The Rails RCE (remote code execution) vulnerability I'm referring to is
https://groups.google.com/forum/?fromgroups=#!topic/rubyonrails-security/61bkgvnSGTQ,
which is caused by exposing YAML and XML parsers. There have been several
subsequent vulnerabilities in this area, e.g.
https://groups.google.com/forum/?fromgroups=#!topic/rubyonrails-security/1h2DR63ViGo,
which involves exposing a JSON parser that happened to operate on YAML
internally. You'll find that similar vulns turned up in various
webframeworks over time (one other case I remember off the top of my head
is a parameter parsing vulnerability in Apache Struts2 related to OGNL).

The DOS vulnerability that would turn up by directly exposing json_decode
as a body parser is the standard HashDOS vulnerability (which exploits
collisions in the array key hashing functions).

Even without exposing additional parser PHP already had its share of
vulnerabilities in this area (e.g. HashDOS and the subsequent RCE that its
fix caused).

I'm not saying that adding additional parsers is bad *per se*, I'm just
saying that you need to be very careful what you add here. The more
automatic body parsers you have the larger the attack surface becomes.

Nikita

---

## #69466 — Adam Harvey — 2013-10-02T18:43:21+00:00

URL: https://externals.io/message/69436#69466 · In reply to: #69437

> 
>
> > […]

I'm not really sure people are confused, actually. There are plenty of
common gotchas that I see daily in ##php, but that isn't one of them.

I like how Alexey broke this down, so I'm going to steal it. :)


> 1. _GET -> _QUERY, _POST -> _FORM

As I hinted at above, I'm -1 on this at first blush. I don't think
it's really that confusing in practice and $_GET and $_POST have a lot
of history (and muscle memory) behind them at this point.

> 2. ignore request-method, trigger body-processing solely on Content-type

Definite +1 here.

> 3. expose body-parsers via php-level API

+1, particularly if it's also available in userland as Alexey got
excited about. :)

Adam

---

## #69470 — johannes@schlueters.de — 2013-10-02T21:40:03+00:00

URL: https://externals.io/message/69436#69470 · In reply to: #69461

> 
> > […]
> 
> Heh, pretty good observation! Didn't think about that. Still not
> buying. $_FORM is derived from "application/x-www-form-urlencoded"
> resp. "multipart/form-data" and $_QUERY is obvious.

Out of curiosity I did some browsing:

- ASP uses Request.QueryString(string name) and Request.Form
- Java Servlets and JSP use ServletRequest.getParameter() for both
- Perl CGI.pm has a param hash for both.

I didn't look really deep though for further specifics :)

So, ASP seems to agree with you, while I see a e difference: In ASP
those are methods which, when used, are always qualified by the Request
Object's name.

A standalone $_QUERY might be confused with the famous $query from
$query= mysql_query().


> > […]
> 
> Valid point. Though, with a long enough time frame it could be done.

Mind that we are talking about changing each and every PHP application.
Each and every PHP tutorial. Each and every book. Each and every
PHP-related tool. Each and every developers mind. Each and every ...

Phasing out register_globals took us some time.

   PHP 4.1, 2001-12-10, $_* introduced and advertised
   PHP 4.2, 2002-04-22, register_globals off by default, causing
                        lots of scream
   PHP 5.4, 2012-03-01, register_globals dropped

That's a deprecation process of ten years for a feature which was
relatively easy to emulate (import_request_variables(), `extract()` etc.)

> > […]
> 
> Yeah, well, there's a lot attached to that cumbersome naming, e.g. all
> *_post_* INI settings etc.
> I should have just resisted proposing that change, but I figured
> testing for backing was cheap.

I think extending the parsing is a good idea and should be done.

And there certainly are quite a few things we would do differently if
PHP was done from scratch, but the days when Rasmus could log in to any
PHP host and apply fixes for new versions are long gone ;-)

This also is a good reminder to take care when adding new features and
to really think those through instead of filling PHP with more and more
stuff (sorry for abusing this thread for the purpose of that rant)

johannes

---

## #69476 — Pierre Joye — 2013-10-03T09:18:14+00:00

URL: https://externals.io/message/69436#69476 · In reply to: #69454

hi!


> 
>
> > […]
>
> I don't think this kind of change is worth it if you just rename two very
> heavily used variables. If something in this direction is changed the
> change should be more thorough (including getting away from superglobals
> and representing the request state by an immutable object).


I totally agree with you here. Unlike the other related changes, the
impact on existing code is much larger here, for little gain. I am in
favor of not touching them, at all.

> > […]
>
> I would *strongly* recommend against adding additional body parsers that
> are automatically invoked based on the content type.

Again, I totally agree.

> Adding additional
> parsers creates a high security risk. E.g. exposing ext/json as it is now
> would open you to a denial of service attack (if I'm not mistaken). There
> has been a long history of security vulnerabilities (both DOS and RCE)
> related to unnecessary or incorrect exposure of request body parsers. A
> prominent recent example are the RCE vulnerabilities in Rails caused by the
> exposure of YAML and JSON parsers.

However I could imagine some new ways to deal with inputs,
rest/http/services friendlier.  But it is a tricky area, both from an
API design and security points of view.

Cheers,
-- 
Pierre

@pierrejoye | http://www.libgd.org

---

## #69484 — Christian Stadler — 2013-10-04T18:38:01+00:00

URL: https://externals.io/message/69436#69484 · In reply to: #69470

Am 02.10.2013 23:40, schrieb Johannes Schlüter:
> 
> > […]
> 
> Out of curiosity I did some browsing:
> 
> - ASP uses Request.QueryString(string name) and Request.Form
> - Java Servlets and JSP use ServletRequest.getParameter() for both
> - Perl CGI.pm has a param hash for both.
> 
> I didn't look really deep though for further specifics :)
> 
> So, ASP seems to agree with you, while I see a e difference: In ASP
> those are methods which, when used, are always qualified by the Request
> Object's name.

Actually I like the idea of having an API to handle everything important
for the HTTP-request and respectively for the response.

e. g.:
HTTPRequest::getFormData(...), which could possibly be aliased by
HTTPRequest::getPOSTData(...) or HTTPRequest::getPOST(...);
as well as
HTTPRequest::getQueryData(...) aliased by
HTTPRequest::getGETData(...) or HTTPRequest::getGET(...);
and HTTPRequest::filterXXX(...) as a replacement for `filter_var()`
and so on

HTTPResponse could include a replacement for htmlspecialchars and
htmlentities (not quite sure, if this fits better to HTTPRequest or
probably into both)
HTTPResponse::buildQuery() would be a replacement für http_build_query
and so on.

To make a long story short: IMHO Every function and superglobal related
to the HTTP-request or -response should be moved to their respective
classes so eveything is under one hood rather than making userland
guessing which function/superglobal/whatever is for what purpose.
As it is now, it is kinda chaotic and confusing to me and probably to
userland, too.

Just may 2 cents about that topic.

Regards,
  Christian Stadler

---

## #69499 — johannes@schlueters.de — 2013-10-07T11:21:24+00:00

URL: https://externals.io/message/69436#69499 · In reply to: #69484

> Actually I like the idea of having an API to handle everything important
> for the HTTP-request and respectively for the response.
> 
> e. g.:
> HTTPRequest::getFormData(...), which could possibly be aliased by
> HTTPRequest::getPOSTData(...) or HTTPRequest::getPOST(...);

We have filter_input(INPUT_POST, ...);

> as well as
> HTTPRequest::getQueryData(...) aliased by
> HTTPRequest::getGETData(...) or HTTPRequest::getGET(...);

We have filter_input(INPUT_GET, ...);

> and HTTPRequest::filterXXX(...) as a replacement for `filter_var()`
> and so on

Why replace something? Are there flaws which can't be fixed? Adding too
many ways to do the same thing is confusing for everybody. If you want
it "object oriented" or such frameworks do great things. The language
should offer a good foundation. (It is my strong believe that we should
move as many "high level" things as possible in libraries)

> HTTPResponse could include a replacement for htmlspecialchars and
> htmlentities (not quite sure, if this fits better to HTTPRequest or
> probably into both)
> HTTPResponse::buildQuery() would be a replacement für http_build_query
> and so on.
> 
> To make a long story short: IMHO Every function and superglobal related
> to the HTTP-request or -response should be moved to their respective
> classes so eveything is under one hood rather than making userland
> guessing which function/superglobal/whatever is for what purpose.
> As it is now, it is kinda chaotic and confusing to me and probably to
> userland, too.

Some of these things might have been named better, back in the past, but
I see no benefit in making those static methods in classes, except maybe
that we then need two hash lookups (class and method tables) instead of
one (function table).

And btw. that design from above already is flawed too:
HTTPResponse::buildQuery() - this has nothing to do with an HTTP
responses. This is i.e. also needed for some stream operations. And also
the escaping is not needed for HTTP, but HTML, even when creating static
HTML pages. ;-)

johannes

---

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