vlucas / bulletphp

A resource-oriented micro PHP framework
http://bulletphp.com
BSD 3-Clause "New" or "Revised" License
416 stars 50 forks source link

Request Params Polluting Globals for Nested Sub-Requests #43

Closed jcbwlkr closed 10 years ago

jcbwlkr commented 10 years ago

When you construct an instance of \Bullet\Request with params we inject those values into the global space. I'm assuming it is because of these lines in the constructor:

    $this->_postParams =& $_POST;
    $this->_getParams =& $_GET;

Consider the following code:

$app = new \Bullet\App();

$app->path("/", function ($request) use ($app) {
    $big    = $app->run(new \Bullet\Request("GET", "name", array("upper" => 1)));
    $little = $app->run(new \Bullet\Request("GET", "name"));
    return $big . $little;
});

$app->path("/name", function ($request) use ($app) {
    return $request->upper ? "JACOB" : "jacob";
});

echo $app->run("GET", "/");

I would expect the output to be JACOBjacob but instead it's JACOBJACOB because the params from the first request are still around for the second.

I don't know the fix, but if you agree that this is a problem then you can use this test to identify the problem.

public function testRequestsDoNotShareParams()
{
    $first_request  = new Bullet\Request('GET', '/', array('foo' => 'bar'));
    $second_request = new Bullet\Request('GET', '/', array());
    $this->assertNull($second_request->foo);
}
vlucas commented 10 years ago

I do agree that this is indeed a problem. Thanks for the test and code for re-producible results.