Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:108661 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 50896 invoked from network); 18 Feb 2020 22:05:38 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 18 Feb 2020 22:05:38 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 20FF21804D9 for ; Tue, 18 Feb 2020 12:21:22 -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.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-wr1-f52.google.com (mail-wr1-f52.google.com [209.85.221.52]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Tue, 18 Feb 2020 12:21:21 -0800 (PST) Received: by mail-wr1-f52.google.com with SMTP id m16so25509225wrx.11 for ; Tue, 18 Feb 2020 12:21:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding:content-language; bh=ICFW8HMPH62pyGcSUUf2Yz16jhtLN2TkrzMN+5KyZ6A=; b=kFUJp68Yt1TZmfHkJG/Wf+ruztvDBI40eT/B97tXJk4EGzpOOEAzkAaCgpfPHV7BrJ vPF8kPFYqrEqkloqkn5YMqiN0NDgOF09EYiZv0X6WZsCeHpmNdXA8pFS/v2/7ptP6NtW GV5UnNFXc8IXtynABmwW29ewjfAtxFcSZAbVtiPawo37PAE0GdesLwU96fOMcCWijMPZ KLXtMhW0A3GCd0Tq6oPmFyDh+cNDSVehvNbGebcPj5qXDYmmpU7FlhHl0gwGWA4/2hcn o+GQoIuh1WZUFk0J9T1mbsKDwr1BZVBw58YbfuwtmXRYcrwuLZwBzr/4iOda3KMzJywt I2Mg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=ICFW8HMPH62pyGcSUUf2Yz16jhtLN2TkrzMN+5KyZ6A=; b=f2aBltSv2ivfNvj8zMG5O+XbQozSw00wkBSrkzt8aHoXuufFWKBqvut8XY7sYqLC7S na5RHO8b/ORcqhpHijB8s7Mr+c2kkmdUn/PPRdNeYr8Ws5msI7ptTTF7zRcjrpLetlsg XF/hFKCK25l6j4z+5iPpfqFB88Pnc1PflRyom+cfsqKiGmEpbKMsUlumsh0ruFdCMc1O lIyOshQdd1dCYfmx9o03ktORRP8q3MDcPFxxu7Tm9FrkF299QLXJvSMDdD/Ca9xSKsEG rwvGxrfNWexa2fvyRZ88yhmH/VYP8XffxT9gRbLpb4WlAQ9OXH1q+Ef0GKC9vlPdMG2B CiBw== X-Gm-Message-State: APjAAAVCNLEzOaXrj7BOoNM4LZVG5K+km0CXfkXLHcmvTYESwcaE+fsS Ch3mzo0s2MwQSiJTYGzqJLhjcb2V X-Google-Smtp-Source: APXvYqywpX9zEZZtMpVEyAsKxGDmYA2H+nw3OJ5ty4JWN/Caiv9fyaGxFOe7nQQk2CDH+RP3InajKw== X-Received: by 2002:adf:edd0:: with SMTP id v16mr30339690wro.310.1582057279713; Tue, 18 Feb 2020 12:21:19 -0800 (PST) Received: from [192.168.0.14] (cpc84253-brig22-2-0-cust114.3-3.cable.virginm.net. [81.108.141.115]) by smtp.googlemail.com with ESMTPSA id g17sm7638930wru.13.2020.02.18.12.21.18 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 18 Feb 2020 12:21:19 -0800 (PST) To: php internals 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> Message-ID: Date: Tue, 18 Feb 2020 20:21:17 +0000 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 MIME-Version: 1.0 In-Reply-To: <8264F6CF-AD55-41E2-9F5A-DAE8942E2B79@pmjones.io> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-GB Subject: Re: [PHP-DEV] RFC: Server-Side Request and Response Objects (v2) From: rowan.collins@gmail.com (Rowan Tommins) On 17/02/2020 15:55, Paul M. Jones wrote: > I apologize in advance for the length of this email. I hate reading walls-of-text, but the answers are necessarily long. I have tried to break it up into bullets where possible for easier reading. No, thank you for taking the time to respond. I've cherry-picked rearranged the quotes in this reply a bit so I can try not to repeat myself too much; let me know if I've taken your words too far out of context. > ...it is likewise valid to say that AdoDB "took functionality that was scattered across a dozen different vendor-specific extensions with different naming and calling conventions, and centralised it into one more-or-less consistent interface." So did PEAR DB, Metabase, MDB, and so on. PDO did it as an extension, instead of in userland, but the goals and outcomes noted were identical. That's a fair point, everything PDO does could be and has been done in userland. There is one thing that couldn't be done outside of an extension, though, which is that PDO doesn't rely on the legacy extensions, it (in theory at least) replaces them. What I think is slightly more relevant, is that PDO makes writing wrappers like ADODB easier, because it contains non-trivial functionality that those wrappers would otherwise have to write. > I don't *expect* anything from existing published library authors > ... > I always thought of the "intended audience" as the much the same as > for any RFC I think perhaps my choice of words has caused a bit of confusion. Perhaps "hope" would have been better than "expect", and "use cases" better than "intended audience". I was trying to draw out two pieces of information: - What's the sales pitch - what do YOU think is great about these classes? - When working out the details, what code should we be picturing using the new classes? I wasn't around when PDO was proposed, but an imaginary "sales pitch" might have gone something like this: - Developers should be able to implement multiple database systems without learning the quirks of each vendor's extension - Library authors shouldn't need to implement the basic functionality of every driver from scratch when the vendor could do it for them - Vendors shouldn't need to decide which API to follow, when we can normalise everything internally - We can offer different result formats and error-handling models out of the box ...and so on > - some [library authors] may find their own work so close to this extension that they migrate over to it entirely. So, there is at least some hope that this will entirely replace some people's existing libraries, even if it doesn't replace the more powerful ones like HttpFoundation. That's probably reasonable. (Note that I've been thinking of "library" fairly loosely - a single class used in a completely private monolithic repo, but which is written to be generic functionality, has much the same role as a public composer package in this case.) > For myself, and as noted by Jan Schneider and others, those benefits center around... This is what I was looking for. Sell it to me! :) > ...a built-in OO-ish request/response object set... "OO-ish" is a wise choice of words here. One of the reasons I'm not terribly keen on this proposal - particularly the request half - is that I'm a bit of an OO purist. By that I mean that I prefer objects that have a strong responsibility, and encapsulate useful behaviour, rather than just spitting out what went in. The response part of the proposal is closer to "real" OO, IMO, because it includes behaviour like manipulating individual headers and cookies. The lack of behaviour also makes it less useful to people writing their own request and response objects: if I have a copy of $_POST and want to put it in my own object property, why would I first pass it to a ServerRequest object, and then get it straight back out again, if the object isn't helping me do anything with that data? That said, I know some people are happy with OO-ish code, some even to the extent of preferring stdClass to an array. So it's not unreasonable to say that this will appeal to developers who are less puritanical about objects than me. > ...that does pretty much just what PHP itself already does... As you say elsewhere, this is useful for helping people migrate to it. The flipside of that is that it ties us into past decisions, rather than evaluating whether those decisions are still what we want. The approach in providing both $files and $uploads arrays is a good compromise - provide the new better way, but also an easy-to-migrate way. I'd love to see them named more distinctly, though, maybe even calling one of them "legacy". I'd probably also make them methods so that the data can be stored once (in the new format) and re-formatted on demand (again, objects as behaviour rather than data). > ...easing their transition away from global state This I find less convincing. To quote from further down the e-mail, I wrote: >> ...you can do almost as much in that direction as the RFC by writing "$get=$_GET; unset($_GET);" The hard problem is that the entry point for a request is in global scope, not a main() or handleRequest() function. and you replied: > Another "hard" problem is carrying those values around in the system once they are decoupled from global state; the objects in this RFC purport to do so. If all the object does is "carry around" a copy of the superglobal arrays, I can write it in about a dozen lines of code. Admittedly, the implementation wouldn't match anyone else's, but if I wanted interoperability, I would need to follow a standard like PSR-7, or match a popular existing library; this does neither. Again, the response object is more powerful in this regard, because we can't currently pass around a list of prepared cookies and trivially output it to the client. Along the lines of my previous message about decoupling concerns, I would personally like the response parts of the proposal split out and re-cast as a kind of "response buffer". That could be useful directly, and it could provide useful functionality to people implementing a full PSR-7 or similar Response object. > I had considered mentioning the dual OO+procedural APIs of mysqli, date, etc. but it seemed too much in an already-long RFC; I'm glad you brought it up, as I did have it in mind. This is an interesting comparison to consider. Just as those extensions have procedural options for people who can't stand objects, the current proposal has objects for people who like "OO-ish". >> Introducing these objects as part of a new calling convention for PHP scripts would definitely add value, and make them a true replacement for the superglobals, but that would be a very different RFC. > That does seem rather ambitious. If you feel that's a valuable thing to add to PHP, perhaps it could be part of a future RFC, maybe even one that uses the objects in this RFC as a starting point. One of the things I don't like about the current proposal is that it's modelled so closely around the current superglobals that I fear it would actually be *harder* to replace them. I find this constraint particularly awkward: > N.b.: It is up to you to make sure the various content-related header > values in |$GLOBALS| match the custom |$content| string. Parsing a request body from an arbitrary source into arrays that match the structure of $_POST and $_FILES would be a really useful feature. It would be something userland libraries could make use of right now, and would fit in nicely with a future where those arrays aren't populated by default. I also really want to see the day when I never have to interact with $_SERVER again. Other than renaming it, this object's design makes that less likely, not more. Imagine if in future we're able to redesign the internals so that there is a dedicated and reliable field for the requested URL; the current object doesn't have anywhere we can put that. If we add it later, it will be too late, code will be written that passes around ServerRequest objects, but relies on the full array of CGI variables to reconstruct the URL. If this object took a more opinionated view of what behaviour to encapsulate, we could simply hide the "server" array completely. Common use cases would be exposed via methods, and rarer use cases would have to be added in userland with their own copy of $_SERVER. Then my dream of deprecating $_SERVER could mean something other than moving it into an object. I hope I haven't left any unfinished sentences as I went back and forth through this! And thanks again for taking the time to engage with me. Regards, -- Rowan Tommins (né Collins) [IMSoP]