Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:97388 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 8017 invoked from network); 13 Dec 2016 16:51:26 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 13 Dec 2016 16:51:26 -0000 Authentication-Results: pb1.pair.com header.from=larry@garfieldtech.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=larry@garfieldtech.com; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain garfieldtech.com from 66.111.4.25 cause and error) X-PHP-List-Original-Sender: larry@garfieldtech.com X-Host-Fingerprint: 66.111.4.25 out1-smtp.messagingengine.com Received: from [66.111.4.25] ([66.111.4.25:44689] helo=out1-smtp.messagingengine.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id F8/92-21185-D0720585 for ; Tue, 13 Dec 2016 11:51:26 -0500 Received: from compute7.internal (compute7.nyi.internal [10.202.2.47]) by mailout.nyi.internal (Postfix) with ESMTP id B79FC205E4 for ; Tue, 13 Dec 2016 11:51:21 -0500 (EST) Received: from frontend2 ([10.202.2.161]) by compute7.internal (MEProxy); Tue, 13 Dec 2016 11:51:21 -0500 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-sender:x-me-sender:x-sasl-enc:x-sasl-enc; s= smtpout; bh=Qf6YOPuQldUcDBh0IVZpuO/gjnE=; b=mll1HNzsCFq4pmPIH5Fk TBuhVpYpPy+CamUHm+jvmq6gJpm2wZXFV9I+3RigXkpTFwN9PhJkCsgeF3rioB/z DKP05jVrE+a894YHcgU0xlV9GbdmCZamI1jfhv3Bk8lUBo5vSq7e0bDotWUhCjpI sKfcVW98b8kUoi6MotR0gxs= X-ME-Sender: X-Sasl-enc: lYx7IlBNBG2lRejnmZYuqiEgqwWRjmK8AftHg7Iz2xCI 1481647881 Received: from [192.168.42.5] (c-50-178-40-84.hsd1.il.comcast.net [50.178.40.84]) by mail.messagingengine.com (Postfix) with ESMTPA id 71F72249CC for ; Tue, 13 Dec 2016 11:51:21 -0500 (EST) To: internals@lists.php.net References: Message-ID: Date: Tue, 13 Dec 2016 10:51:21 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.5.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Subject: Re: [PHP-DEV] [RFC Proposal] Introducing New Global Variable to Support Other HTTP Methods and Content Types From: larry@garfieldtech.com (Larry Garfield) On 12/13/2016 07:38 AM, Dejan Stošić wrote: > *Disclaimer* > Sorry if this has been discussed before, i tried searching, but i couldn't > find much information. > > I probably have nowhere near the experience of you guys, so i apologize if > i overlooked something obvious. I'd like to hear if this is a good or a > terrible idea and the reasons behind it. I'm new to the world of core PHP > development, but if this makes sense, i could try working on this myself. > > *Introduction* > The world of web dev has shifted a lot toward API development in the last > few years. Specifically - REST APIs are becoming the industry standard. > Among other things, one of the core principles of REST is to utilize all > HTTP methods - (GET, POST, PUT, PATCH, DELETE...). > > *The problem* > Currently, PHP will parse the incoming HTTP request body only for GET > requests (and store the data in superglobal $_GET) and for POST requests > (and store the data in $_POST). > Additionally it will parse the data only for > *application/x-www-form-urlencoded* or *multipart/form-data *HTTP Content > types. > There are other 3rd party libraries and packages that enhance this and > enable parsing for other request methods and content types, but i feel like > this should have native support at this point. > > *Goal* > Ideally, PHP should natively parse the incoming HTTP request body for all > request methods, not only for GET and POST. I guess that completely > replacing the $_POST and $_GET is out of the question as it would lead to > no backward compatibility. Maybe an additional superglobal could be > introduced ($_DATA)? > > > Thanks This would be infeasible. Parse it how? The $_GET and $_POST variables are really misnamed. $_GET is "URI query parameters" (which have nothing to do with the body, and can be present for any HTTP method) and $_POST is, as you note, "the request body parsed according to x-www-form-urlencoded rules". If the content type is something else, then we don't know how to parse it. We could make educated guesses in some cases, but then how do you know which one to guess? Is it a supported guess? That's a very deep rabbit hole. Remember, just because a request is a POST doesn't mean it's x-www.-form-urlencoded, and just because it's a PUT doesn't mean it isn't. The better solution is what's already available: Read the input stream directly and parse it yourself in user-space using whatever parser you know to be appropriate for your application. PSR-7 has a built-in mechanism for tracking and storing the parsed result, but the actual parsing itself is up to you. Besides all that, adding more global variables to the SAPI is just a terrible idea in general as global variables are where architecture goes to die. --Larry Garfield