Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:78763 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 36091 invoked from network); 6 Nov 2014 01:29:53 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 6 Nov 2014 01:29:53 -0000 Authentication-Results: pb1.pair.com header.from=theanomaly.is@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=theanomaly.is@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.46 as permitted sender) X-PHP-List-Original-Sender: theanomaly.is@gmail.com X-Host-Fingerprint: 74.125.82.46 mail-wg0-f46.google.com Received: from [74.125.82.46] ([74.125.82.46:35678] helo=mail-wg0-f46.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 52/21-28384-E0FCA545 for ; Wed, 05 Nov 2014 20:29:51 -0500 Received: by mail-wg0-f46.google.com with SMTP id x13so59106wgg.19 for ; Wed, 05 Nov 2014 17:29:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=wgBxlbY90W3pgtRMEWLDz1qK1BLvSky3HDaxrYvGm/s=; b=OgVCQFAB8cwlLYpIzaq3yCQQM3FjXWZlaJJ1pgaIEZObpaSJJsnQ3ICI4U2AVZPYR1 ISF+eePsZ7/Y8jFDOPvK1VBFQ9hz2q1TO2lwqC0i/ASjWCj6N4aTrk6+pHJckWxY+VXA SqwEndstq+AUFBVoDqt5d7VvivAvfsze/LueNjsWRcz1QLjWPVXzVCN8oFQzRPLv+xGt wDT3mJrNnsSFgQUOjdOq0PBQDi+7kn/I2qWlqFrlD1wGq6EgwC3M3rFcvAdj6fTvAjzG W2rFy2o1XKk1ujwR0gerbkCdpPC6hyMTk7SOV4oZrFViiqToUMrZD8XEvqrBDXn5fHSO d9dw== MIME-Version: 1.0 X-Received: by 10.194.77.142 with SMTP id s14mr1204535wjw.94.1415237387382; Wed, 05 Nov 2014 17:29:47 -0800 (PST) Received: by 10.216.123.4 with HTTP; Wed, 5 Nov 2014 17:29:47 -0800 (PST) In-Reply-To: <1DDB6E05-3143-4A74-8B13-AF85222579BA@ajf.me> References: <1DDB6E05-3143-4A74-8B13-AF85222579BA@ajf.me> Date: Wed, 5 Nov 2014 20:29:47 -0500 Message-ID: To: Andrea Faulds Cc: Patrick ALLAERT , PHP Internals Content-Type: multipart/alternative; boundary=047d7bfd0292bf73d4050726a1ff Subject: Re: [PHP-DEV] New Standardized HTTP Interface From: theanomaly.is@gmail.com (Sherif Ramadan) --047d7bfd0292bf73d4050726a1ff Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Wed, Nov 5, 2014 at 7:31 PM, Andrea Faulds wrote: > > > On 5 Nov 2014, at 22:29, Sherif Ramadan wrote= : > > > > From all the people I've spoken with that have a problem with handling > PUT > > requests in PHP, it seems that they'd rather have PHP populate > > $_FILES/$_POST automatically in this case. Which would be relatively ea= sy > > to do by modifying the default post reader function in the SAPI > > http://lxr.php.net/xref/PHP_5_6/main/php_content_types.c#51 however, > that > > is itself a small BC break. > > > > Does anyone have any recommendations on what they think the best approa= ch > > is? I'd appreciate any feedback/suggestions/constructive-criticism. > Thanks! > > I don=E2=80=99t think auto-populating for PUT/DELETE etc. is a good idea,= they=E2=80=99re > quite different semantically. If I send a DELETE request to code expectin= g > a POST, and PHP pretends it=E2=80=99s a POST request, that=E2=80=99s bad. > So you're actually describing two semi-different problems here. One is that PHP doesn't actually inform you of the HTTP request VERB strictly through the naming of the super global variables $_POST and $_GET. However, $_POST being populated, right now, in PHP, strictly means the request verb was POST and that the content-type header received was multipart form data. Which means that sending something like a JSON payload (Content-type application/x-json or whatever) in the body of a POST request still doesn't populate the $_POST super global variable even though the HTTP request VERB was indeed POST. The other problem is that the semantics of REST itself are quite different from how PHP currently deals with the request data. In that PHP only cares about form data. However, this is quite antiquated with todays' modern use of HTTP growing in API-specific functionality. For example, companies like Twitter and Tumblr, demonstrate a vast majority of their traffic currently coming in at the API-level where things are usually handled in a RESTful manner. So for the PHP power houses today, PHP doesn't quite lend itself well to dealing with these problems first-hand. Instead we have to hack our way around them in userland, which can be more error-prone and less obvious= . > > However, I think the solution is simple: Add a function to do > multipart/form-data parsing. Not a suite of functions, not a class, just > one simple function. That way, for the few people that need it, they can = do > $_POST =3D multipart_form_data_parse(file_get_contents(=E2=80=98php://inp= ut')); and > their problem=E2=80=99s solved. > If we can=E2=80=99t expose the parser, we could also just add a function = to force > population (force_parse_post_data() or something?). Again, this allows th= e > few that need this to do so explicitly, but doesn=E2=80=99t make $_POST a= llow it > for everyone else. > While that solution solves one specific problem (dealing with multipart form data of request types other than POST), it doesn't quite tackle some of the broader issues of dealing with incoming HTTP request in PHP that I would like to tackle. I also think you're diminishing scope of this problem and the number of people affected by it. You not only have to think of the number of programmers dealing with the code, but the number of end-users indirectly affected by the problem as well. PHP is primarily a web-oriented language, and I think as such it should deal with these kinds of issues more readily. If you take a good look at the number of web-based APIs out there and how certain PHP client libraries try to deal with these kinds of problems the solutions are sometimes very poorly implemented or just outright wrong. We solved password hashing dilemmas with password_hash for a similar reason in PHP. In that people were just doing it wrong and didn't know any better. So I think making a more robust, and simpler interface to deal with these kinds of issues will encourage people to get it right in the future. > -- > Andrea Faulds > http://ajf.me/ > > > > > --047d7bfd0292bf73d4050726a1ff--