PHP RFC: Server-Side Request and Response Objects
- Version: 0.2
- Date: 2016-12-21
- Author: Paul M. Jones, firstname.lastname@example.org
- Status: Under Discussion
- First Published at: http://wiki.php.net/rfc/request_response
PHP is and should remain:
1) a pragmatic web-focused language
2) a loosely typed language
3) a language which caters to the skill-levels and platforms of a wide range of users
This RFC should move PHP forward following his vision. As said by Zeev Suraski “Consider only features which have significant traction to a large chunk of our userbase, and not something that could be useful in some extremely specialized edge cases […] Make sure you think about the full context, the huge audience out there, the consequences of making the learning curve steeper with every new feature, and the scope of the goodness that those new features bring.”
From time to time we've all heard the complaint that PHP has no built-in request object to represent the execution environment. Userland ends up writing these themselves, and those are usually tied to a specific library collection or framework. The same is true for a response object, to handle the output going back to the web client. I've written them myself more than once, as have others here.
After doing some library and framework research it looks like there is a reasonably common subset of request/response functionality across all the userland implementations. That functionality also appears useful to non-framework users.
I next put together a userland implementation of the common subset, which John Boehr then used as a reference point for the C version. It is PHP 7.x only. The proposal below is the result of that work.
This extension provides server-side request and response objects for PHP. These are not HTTP message objects proper. They are more like wrappers for existing global PHP variables and functions, with some limited additional convenience functionality.
This extension defines two classes in the global namespace:
- ServerRequest, composed of read-only copies of PHP superglobals and some other commonly-used values, with methods for adding application-specific request information in immutable fashion.
- ServerResponse, essentially a wrapper around (and buffer for) response-related PHP functions, with some additional convenience methods, and self-sending capability.
Backward Incompatible Changes
Proposed PHP Version(s)
Next PHP 7.x.
To Existing Extensions
Make sure there are no open issues when the vote starts!
Unaffected PHP Functionality
The remainder of PHP should remain unaffected.
Possible support for HTTP/2 and server push.
Proposed Voting Choices
This counts as a language change, so a supermajority is required.
Patches and Tests
The C code for the extension and tests are at https://github.com/pmjones/ext-request .
After the project is implemented, this section should contain
- the version(s) it was merged to
- a link to the git commit(s)
- a link to the PHP manual entry for the feature
Links to external references, discussions or RFCs
Keep this updated with features that were discussed on the mail lists.