Currently PHP only parse request body when the Content-Type is application/x-www-form-urlencoded or multipart/form-data.[1] This RFC proposes to parse request body with Content-Type application/json or text/json.
It's very common for javascript library to send JSON payload now, however, PHP doesn't have built-in support for it. Userland developers have to deserialize it by themselves, which is inefficient and inconvenient. This RFC proposes to reuse the ability from ext/json to deserialize the payload and fill in $_POST
.
For example,
curl -i -H "Content-Type: application/json" -X POST http://localhost:8000 -d '{"foo":"123","bar":456}'
will get
var_dump($_POST); /* array(2) { ["foo"]=> string(3) "123" ["bar"]=> int(456) } */
Some edge cases:
$_POST
will be an empty array.$_POST
will be an empty array.JSON_BIGINT_AS_STRING
is enabled. There won't be an option/setting for this because this is how $_POST
deal with large numbers.
$_POST
will be filled instead of an empty value when Content-Type is application/json or text/json.
Next PHP 7.x
New SAPI_POST_HANDLER_FUNC
will be introduced to implement this RFC.
This RFC doesn't introduce any new settings.
Requires a 2/3 majority to pass.
Links to any external patches and tests go here.
If there is no patch, make it clear who will create a patch, or whether a volunteer to help with implementation is needed.
Make it clear if the patch is intended to be the final patch, or is just a prototype.
For changes affecting the core language, you should also provide a patch for the language specification.
After the project is implemented, this section should contain