slimphp / Slim

Slim is a PHP micro framework that helps you quickly write simple yet powerful web applications and APIs.
http://slimframework.com
MIT License
11.98k stars 1.95k forks source link

[Discussion] Status Code as Constants #2310

Closed Raistlfiren closed 7 years ago

Raistlfiren commented 7 years ago

Hey,

I just wanted to bring up a discussion for later releases on adding the status codes as constants to the Response class. Similarly to http://api.symfony.com/3.4/Symfony/Component/HttpFoundation/Response.html

I feel like it is much more beneficial coding using constants instead of status code of say 422 or 400. For example, users can now use the constants in their code like Response::HTTP_UNPROCESSABLE_ENTITY or Response::HTTP_BAD_REQUEST.

Thoughts?

Thanks for your time and consideration.

geggleto commented 7 years ago

We already have this baked in.

https://github.com/slimphp/Slim/blob/3.x/Slim/Http/Response.php#L48-L118

I don't see the problem it solves. If you don't know the status code you wish to use then you need to know the name it uses... which often times is not really a name that you think of... example 418 => 'I\'m a teapot',

mahagr commented 7 years ago

To me, error codes are more clear than the titles of the errors. So no, it will only make things worse.

akrabat commented 7 years ago

I'm not against it. I would use STATUS_XYZ rather than HTTP_XYZ personally, though.

geggleto commented 7 years ago

@akrabat Nothing can really be done on 3.x... but this should be raised on slimphp/http

geggleto commented 7 years ago

Going to close this here, it's open on Http and we can change the constants in 4.x