I am using Zend Framework 2's AbstractRestfulController
to implement a CRUD API in our project. Using the PUT HTTP method invokes the logic for updating an existing entity.
When receiving a PUT request, the AbstractRestfulController
transforms the request body to an array using PHP's parse_str
function, but this function does not do what it is supposed to do.
Because it gave me odd results, I tried parse_str
with the sample data provided in the PHP docs:
// sample data from the PHP docs
$content = "first=value&arr[]=foo+bar&arr[]=baz";
// put the parsed variables into $parsedParams
parse_str($content, $parsedParams);
var_dump
ing $parsedParams
gives me the following
array(5) {
["first"]=> string(1) "v"
["lue"]=> string(0) ""
["rr"]=> array(2) {
[0]=> string(5) "foo b"
[1]=> string(1) "b"
}
["r"]=> string(0) ""
["z"]=> string(0) ""
}
Apparently the character "a" confuses parse_str
, but I have absolutely no idea what's causing this odd behavior. The encoding of the PHP file is UTF-8, server is running Ubuntu 14.04 with PHP 5.4 as a Apache 2.4 module inside a Vagrant environment.
What may be the cause of this? I read about issues with the HTML entity &
instead of plain &
's, but that doesn't seem to apply here.
UPDATE
I just ran the same code on the command line in interactive mode via SSH
ing into the Vagrant machine. In interactive mode parse_str
works without problem! I then ran my test script from the command line via $ php /var/www/test.php
which also worked properly.
Is this a problem with the Apache PHP module or configuration?