diff --git a/src/Symfony/Component/HttpFoundation/Request.php b/src/Symfony/Component/HttpFoundation/Request.php index 50669a2c2b045..5ddadf4d0d2e3 100644 --- a/src/Symfony/Component/HttpFoundation/Request.php +++ b/src/Symfony/Component/HttpFoundation/Request.php @@ -1410,10 +1410,10 @@ public function setFormat($format, $mimeTypes) public function getRequestFormat($default = 'html') { if (null === $this->format) { - $this->format = $this->attributes->get('_format', $default); + $this->format = $this->attributes->get('_format'); } - return $this->format; + return null === $this->format ? $default : $this->format; } /** diff --git a/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php b/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php index 0e80757236096..0eb2f7b510632 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php @@ -1438,6 +1438,11 @@ public function testGetRequestFormat() $request = new Request(); $this->assertEquals('html', $request->getRequestFormat()); + // Ensure that setting different default values over time is possible, + // aka. setRequestFormat determines the state. + $this->assertEquals('json', $request->getRequestFormat('json')); + $this->assertEquals('html', $request->getRequestFormat('html')); + $request = new Request(); $this->assertNull($request->getRequestFormat(null));