Archives


Master Symfony2 fundamentals

Be trained by SensioLabs experts (2 to 6 day sessions -- French or English).
trainings.sensiolabs.com

Discover the SensioLabs Support

Access to the SensioLabs Competency Center for an exclusive and tailor-made support on Symfony
sensiolabs.com

Fabien Potencier
New in Symfony 2.4: Using Constants for HTTP Status Code
by Fabien Potencier – October 20, 2013 – 4 comments

Contributed by
Fabien Potencier
in #8820.

Instead of relying on HTTP status code as integer in your code, which might look like magic values to some, it might be more readable to use the new constants provided by the Symfony Response class in 2.4:

1
2
3
use Symfony\Component\HttpFoundation\Response;

$this->assertEquals(Response::HTTP_OK, $response->getStatusCode());

See the Response class for a full list of supported constants.

Comments RSS

  • Lukas Kahwe Smith
    #1 Lukas Kahwe Smith said on the 2013/10/20 at 10:40
    Just FYI, this list of constant has been part of FOSRestBundle (and the FOSRest lib which is now deprecated) for a while but its of course much more convenient to have it right in core.
  • Mohamed Aymen
    #2 Mohamed Aymen said on the 2013/10/24 at 18:53
    nice
  • Oscar Balladares Moya
    #3 Oscar Balladares Moya said on the 2013/10/27 at 21:07
    I was wondering why we didn't have this feature before. Little but awesome :)
  • Juan Francisco Fernández
    #4 Juan Francisco Fernández said on the 2013/10/27 at 21:15
    Small but smart change!