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

Comments

Projects
None yet
3 participants
@stamster
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

This comment has been minimized.

Show comment
Hide comment
@stamster

stamster Jun 16, 2017

Contributor

Thanks @sergeyklay

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

Contributor

stamster commented Jun 16, 2017

Thanks @sergeyklay

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

@Jurigag

This comment has been minimized.

Show comment
Hide comment
@Jurigag

Jurigag Jun 17, 2017

Member

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

Member

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

This comment has been minimized.

Show comment
Hide comment
@stamster

stamster Jun 20, 2017

Contributor

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.

Contributor

stamster commented Jun 20, 2017

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

Changes wrong behavior of Phalcon\Http\Response getStatusCode() metho…
…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

This comment has been minimized.

Show comment
Hide comment
@sergeyklay

sergeyklay Jun 21, 2017

Member

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

Member

sergeyklay commented Jun 21, 2017

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

@sergeyklay sergeyklay closed this Jun 21, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment