Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:69455 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 37828 invoked from network); 2 Oct 2013 15:29:52 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 2 Oct 2013 15:29:52 -0000 Authentication-Results: pb1.pair.com header.from=rdlowrey@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=rdlowrey@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.215.172 as permitted sender) X-PHP-List-Original-Sender: rdlowrey@gmail.com X-Host-Fingerprint: 209.85.215.172 mail-ea0-f172.google.com Received: from [209.85.215.172] ([209.85.215.172:42037] helo=mail-ea0-f172.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 89/D9-23255-0FB3C425 for ; Wed, 02 Oct 2013 11:29:52 -0400 Received: by mail-ea0-f172.google.com with SMTP id r16so486437ead.17 for ; Wed, 02 Oct 2013 08:29:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=w732uFBUp1hf0qnSrc7CsQ0pVs3pWkA2G4aeTPok9mA=; b=xcVs7RH3Y9LXRxE90X0cZU0/FisNmL0bjr3DISA9ZbM4vvDcjIQbr0bAVIewzPZtse pJ+4qR1a2c7Zh4wNl2NTVUVkGwflSmXvuiSTVmB60F42cmGVSh5CIcdTrS3c7tpsN7++ E8epnTvWo5KSa+RZqytlCAGZNqOhVLfii33Zf38Sz0fSIJF3lfuuq51RNYxOMKRbsA1T URrqC+wjJaugJZqfw2t2IqK7qLDd7dwWdxXxYsdnzgbEts9nikQuLWHzNAWg2Qw5Bcye BfDEzM40FZ6MzIzjMhGK+dYCYQKE8yCowe3V1xZwGbb8Ob0oUCvskPLe/wXUgI4VZ5KH GHoA== MIME-Version: 1.0 X-Received: by 10.15.107.135 with SMTP id cb7mr3984588eeb.60.1380727788575; Wed, 02 Oct 2013 08:29:48 -0700 (PDT) Received: by 10.223.149.83 with HTTP; Wed, 2 Oct 2013 08:29:48 -0700 (PDT) Date: Wed, 2 Oct 2013 11:29:48 -0400 Message-ID: To: "internals@lists.php.net" Content-Type: multipart/alternative; boundary=089e01634c7c5ecd1904e7c3bd28 Subject: Re: HTTP supergloblas and request body/query (was: Parsing PUT data) From: rdlowrey@gmail.com (Daniel Lowrey) --089e01634c7c5ecd1904e7c3bd28 Content-Type: text/plain; charset=ISO-8859-1 The superglobals are a hopelessly poor abstraction. Can we stop trying to put the proverbial gold ring in the pig's snout on this? While a change to `$_QUERY` and `$_BODY` would undoubtedly be an improvement I don't think the massive BC breaks that would result are justified by simply improving variable names. The problem isn't nomenclature; it's globally mutable data structures whose key-value nature aren't a good fit for the unrestricted possibilities of HTTP. You can't efficiently model an HTTP request with associative arrays. Period. The other elephant in the room is that your average wordpress developer will continue to use `$_GET` and `$_POST` regardless. So any improvements that are made should be targeted at professional developers. The obvious thing to do here is to introduce an entirely separate abstraction that can be used by professional developers without eliminating the exceedingly simple superglobal abstraction (hello, BC easily retained). Something like the following would be an infinitely superior solution: interface HttpRequest { function getMethod(); function getContentType(); function getContentLength(); function getBody(); function getBodyStream(); function hasHeader($fieldName); function getHeader($fieldName); function hasFormField($fieldName); function getFormField($fieldName); function hasCookie($fieldName); function getCookie($fieldName); } By adding a global function such as `get_request()` that returns the immutable request object you get all the functionality you could want: 1. Entity body parsing (for cookies or form data) could be done JIT 2. Userland code can easily typehint against the request 3. No more mutability, eminently testable 4. Eliminates the need for `$_GET`, `$_POST`, `$_COOKIE`, etc ... This is simply an example of a much better way to model HTTP requests -- it's not a suggestion for a final implementation. But IMO if we're going to fix this then we should really fix it and not continuously tickle the same broken abstraction. Some other thoughts ... > While we're at it, can we remove the quirk that existed due to register_globals > where periods and such are replaced with underscores? I think "fixing" this is a bad idea. You simply can't allow invalid variable name characters as part of these keys. That's asking for trouble. This problem is completely nullified with an immutable request object, though. > 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. Agreed. It's best to retain the thoroughly tested existing parser functionality for things like multipart, url-encoded forms and cookies. These can easily be reused as part of a JIT object-based solution. Everything else should be the user's responsibility (until proven so ubiquitous as to be useful at the language level). Manual userland parsing should be trivial as long as the raw entity body is available. --089e01634c7c5ecd1904e7c3bd28--