Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Phalcon\Http\Response getStatusCode() returns full string instead of int code #12895

Closed
stamster opened this issue Jun 15, 2017 · 4 comments
Closed
Assignees
Labels
bug A bug report status: low Low
Milestone

Comments

@stamster
Copy link
Contributor

stamster commented Jun 15, 2017

Expected and Actual Behavior

   $http_status = 422;
   $this->response->setStatusCode($http_status);
  var_dump($this->response->getStatusCode());

Expected: int(422) or string(3) "422"

Actual result is:
string(24) "422 Unprocessable Entity"

Provide minimal script to reproduce the issue

$res = new Phalcon\Http\Response();
$res->setStatusCode(422);
var_dump($res->getStatusCode());

Details

  • Phalcon version: 3.1.2
  • PHP Version: 7.0.18
  • Operating System: GNU/Linux, Ubuntu 16.04 LTS
  • Installation type: Compiling from source
  • Zephir version (if any): 0.9.7-1fae5e50ac
  • Server: Nginx
  • Other related info (Database, table schema): n/a

Exactly same code works w/o this issue on PHP 5.6.30 and same Phalcon version / setup.

@sergeyklay sergeyklay added this to the unplanned milestone Jun 15, 2017
@sergeyklay sergeyklay self-assigned this Jun 15, 2017
@stamster
Copy link
Contributor Author

Thanks @sergeyklay

It amazes me how this is different between PHP versions, and not Phalcon versions.

@Jurigag
Copy link
Contributor

Jurigag commented Jun 17, 2017

headers->set("Status", code . " " . message); fomr setStatusCode

return this->getHeaders()->get("Status"); from getStatusCode, from code it should return really 422 Unprocessable Entity not sure why there is only number on php 5

@stamster
Copy link
Contributor Author

Well now I'm not sure whenever the issue was PHP 5 or my Database default values. More precisely, if database had column defined as int string(24) "422 Unprocessable Entity" will get trimmed out by default and database will only have int 422 saved in that row.

Nevertheless, this is definitely a bug - now confirmed exact same behavior on both PHP 5.6.30 and PHP 7.0.x. As we can see in zephir sources, surely this method will return full string, which is not desirable.

stamster added a commit to stamster/cphalcon that referenced this issue Jun 20, 2017
…d to return status code only as int instead of full string (see phalcon#12895)
stamster added a commit to stamster/cphalcon that referenced this issue Jun 20, 2017
stamster added a commit to stamster/cphalcon that referenced this issue Jun 20, 2017
stamster added a commit to stamster/cphalcon that referenced this issue Jun 20, 2017
stamster added a commit to stamster/cphalcon that referenced this issue Jun 21, 2017
@sergeyklay
Copy link
Contributor

Fixed in the 3.2.x branch. Thank you for contributing.

@niden niden added bug A bug report status: low Low and removed Bug - Low labels Dec 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A bug report status: low Low
Projects
None yet
Development

No branches or pull requests

4 participants