Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:108771 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 20046 invoked from network); 26 Feb 2020 18:24:53 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 26 Feb 2020 18:24:53 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id CCF6118050B for ; Wed, 26 Feb 2020 08:42:34 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS29169 217.70.176.0/20 X-Spam-Virus: No X-Envelope-From: Received: from relay1-d.mail.gandi.net (relay1-d.mail.gandi.net [217.70.183.193]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Wed, 26 Feb 2020 08:42:33 -0800 (PST) X-Originating-IP: 107.223.28.39 Received: from samurai.attlocal.net (107-223-28-39.lightspeed.nsvltn.sbcglobal.net [107.223.28.39]) (Authenticated sender: pmjones@pmjones.io) by relay1-d.mail.gandi.net (Postfix) with ESMTPSA id 71C65240007; Wed, 26 Feb 2020 16:42:31 +0000 (UTC) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 13.0 \(3608.60.0.2.5\)) In-Reply-To: <5ec7b4a7-508b-270b-916f-0504a116196c@gmail.com> Date: Wed, 26 Feb 2020 10:42:29 -0600 Cc: php internals Content-Transfer-Encoding: quoted-printable Message-ID: <30112AFF-38F9-44D4-9D2F-03A32019764F@pmjones.io> References: <50BD013E-CF72-414C-BBC0-A7A2E45CBDDB@pmjones.io> <5904137.fSVIMsojiJ@mcmic-probook> <3DDBFBA4-8D3A-46C5-9A10-B093A5E2386B@pmjones.io> <54493258-B52E-442A-A11D-82E1D4C7DE5E@gmail.com> <8264F6CF-AD55-41E2-9F5A-DAE8942E2B79@pmjones.io> <1BF3D29A-04C6-4A82-9216-EAE991A38916@pmjones.io> <10388b3a-3402-a6dc-3837-b03d735edf46@gmail.com> <5ec7b4a7-508b-270b-916f-0504a116196c@gmail.com> To: Rowan Tommins X-Mailer: Apple Mail (2.3608.60.0.2.5) Subject: Re: [PHP-DEV] RFC: Server-Side Request and Response Objects (v2) From: pmjones@pmjones.io ("Paul M. Jones") Hi Rowan, > On Feb 24, 2020, at 15:47, Rowan Tommins = wrote: >=20 > Hi Paul, >=20 > I left this thread to settle a bit, because I felt we were going round = in circles a bit. I think there's some fundamental differences in = outlook that no amount of discussion is going to resolve, so I've = trimmed this reply to the more specific points. I appreciate you taking the trouble; thanks. >> Which is the purpose of the documentation; it describes the = differences between $files and $uploads. >=20 > That's no reason not to *try* for descriptive names, though. I presume = the idea is that one array is expected to be more useful for new code, = and the other is mostly there for compatibility with old code? If so, = perhaps the names could reflect that somehow. Your presumption is correct! And your point on trying for better names = is well-taken -- though I think these are "expected" names, based on my = research into existing implementations. The most-common names are ... - the word "files" for unparsed or unmodified $_FILES values, leading me = to think $files is well-understood - the words "upload(s)", "fileUpload(s)", or "uploadedFile(s)" for = parsed, transformed, or restructured $_FILES values, leading me to think = $uploads is well-understood And the current users of the 1.x version have not reported confusion or = trouble with the names as they are. Having said that, I am open to suggestion here. What names do you think = would be better than the ones presented, contra pre-existing work from = other authors? > Incidentally, the current documentation doesn't describe the = differences particularly well, just saying one is "more like $_POST". = Some details of the structure, or examples comparing the two arrays, = would be useful. Good call! On your suggestion, I have added details at = . Suggestions = for improvement are welcome. >>> I was actually thinking of the opposite: given a request body which = didn't come from global state, but which contains data in = multipart/form-data format, extract the key-value pairs and attached = files. >> Is that something PHP "itself" already does? If not, I have to = consider it out-of-scope for this RFC. >=20 >=20 > a) Yes: Every time you submit a form as multipart/form-data, PHP = parses it into the global state. If this object is aiming to abstract = away from global state, then having a non-global-state parser for that = seems consistent. >=20 > b) No: There is no function which currently takes a string and returns = an array for this scenario. However, that's true of other features you = have included, such as parsing accept headers, or even extracting just = HTTP headers from a copy of the $_SERVER array. Quite a lot packed into four sentences; I'll try to address all of it. - First off, "yes and no" is a great answer, the most-accurate one = possible. It highlights what I'm getting at: PHP transforms the content = body into $_POST under some circumstances but not others. The RFC = proposes to honor that existing PHP behavior. - "If this object is aiming to abstract away from global state" -- well, = global *mutable* state, anyway, per our last exchange (and noted again = below). - "There is no function which currently takes a string and returns an = array for this scenario." -- True, though (and not to undermine my own = case) there is json_decode(), which can return an array. But then the = trouble is how to decide when to apply it, and with what parameters, and = how to trap & report errors, etc., all of which adds complexity to what = I think ought to be a simple object. And then once special treatment is = given to JSON, what about XML? Etc., etc. Given all that, it strikes me = that the cases not already served by PHP for parsing the body content = into $_POST are best left to consumers of ServerRequest. - "However, that's true of other features you have included" -- also = true, though those are informed by research into existing = implementations, and provide what appear to be commonly- or = frequently-needed values and structures. (You may opine this is = contradictory, in which case I will respond as Whitman: "Do I contradict = myself? Very well, then I contradict myself. I am large, I contain = multitudes." ;-) >> Your point on global state is well-taken; I will try to remember in = future to phrase it as "global *mutable* state." (AFAICT, php://input is = not mutable, though as you correctly point out, it is global.) >=20 > This distinction seems unnecessary. Once created, the object avoids = global state because it is self-contained, and the fact that it's = read-only is a separate attribute. We're really just talking about ways = to construct that self-contained state, and "everything from global = state" or "nothing from global state" seem like more natural options = than "one thing from global state, everything else not". I agree that the default $content value is an exception to everything = else in ServerRequest. While it stays read-only, it does get read from = php://input each time you refer to it. The alternative is to read from php://input once at construction time = (when the construct $content argument is null) and retain that value in = $content from the start. But in that case, when you have very large = content bodies (as when there are PUT file uploads or other large = payloads), then ServerRequest takes up a lot of memory, when it might = not ever be used directly. Yes, "it might never be used" could be true = of every element on ServerRequest, but the maximum memory use for those = other elements tends to be rather smaller. In the end, letting $content read from php://input on the fly is a = reasonable tradeoff; an exception that tests the rule, if you will. Over to you! --=20 Paul M. Jones pmjones@pmjones.io http://paul-m-jones.com Modernizing Legacy Applications in PHP https://leanpub.com/mlaphp Solving the N+1 Problem in PHP https://leanpub.com/sn1php