Issue Type: Docs: Problem Created: 2008-07-08T03:20:36.000+0000 Last Updated: 2008-09-02T10:39:41.000+0000 Status: Resolved Fix version(s): - 1.6.0 (02/Sep/08)
Reporter: AmirBehzad Eslami (behzad) Assignee: Rob Allen (rob) Tags: - Zend_Controller
Related issues: Attachments: - zf3596-option1.patch
In the zf-manual, there is a sample code for Redirector action helper:
http://framework.zend.com/manual/en/… 126.96.36.199.2. Basic Usage Examples
The example code passes the HTTP-code 303 as string , i.e. '303'. But redirector assumes the provided code invalid, and an exception will thrown.
$this->_helper->_redirector->setCode(303) works fine, but $this->_helper->_redirector->setCode("303") failes.
@see: Zend/Controller/Action/Helper/Redirector.php (Line 89) @setHttpResponseCode() @see: Zend/Controller/Response/Abstract.php (Line 242) @ _checkCode()
More info is available on the mailing list: http://firstname.lastname@example.org/…
Posted by Till Klampaeckel (till) on 2008-07-25T19:05:00.000+0000
Just to comment on this since you emailed the mailinglist about it...
Personally, this is a non-issue for me. HTTP status codes are numbers, not strings. Also, contrary to popular believe there are also types in PHP: http://www.php.net/manual/en/language.types.php
IMHO it's good that the redirector is explicit on this issue and demands a certain type. Casting in the redirector is more expensive cause that would imply casting for everyone who uses the framework, not just for people who tend to be a bit more loose on variables. :) (With no offense meant.)
If you are not sure about what you pass into it, try the following code snippet:
<pre class="highlight"> $code = '404'; $this->_helper->_redirector->setCode(intval($code));
Posted by Matthew Weier O'Phinney (matthew) on 2008-07-26T06:19:45.000+0000
Marking as a documentation issue, though we may choose to update the code to allow casting strings where ($string == intval($string)).
Scheduling for next minor release (1.6.0GA)
Posted by Rob Allen (rob) on 2008-08-07T12:34:52.000+0000
Given that the current code has an is_int() call, casting to int on entry would be more efficient. Also the exception message given when you pass in a string is less than helpful as the code:
<pre class="highlight"> $code = '301'; $this->_helper->_redirector->setCode(intval($code));
gives the exception message:
<pre class="highlight"> Invalid redirect HTTP status code (301)
Casting to an int solves this far more neatly and is much more programmer friendly to boot.
2 patches attached. 1. zf3596-option1.patch: Simple cast to int (my preference) 2. zf3596-option2.patch: Test for string first (as per Matthew's comment)
Both patches have appropriate unit test.
Personally, I'd like to see patch 1 applied as it's "cleaner" and more efficient in my opinion.
Would someone mind committing it as I don't think I have the karma.
Posted by Rob Allen (rob) on 2008-08-07T12:54:36.000+0000
Fixed on trunk in svn r10778 and on release-1.6 in svn r10779.
Posted by Rob Allen (rob) on 2008-08-07T12:56:22.000+0000
For posterity, I should probably note that I talked to Matthew Weier O'Phinney on IRC and he agreed with applying the option 1 patch to both trunk and the release-1.6 branch.
Posted by AmirBehzad Eslami (behzad) on 2008-08-10T10:31:15.000+0000
Posted by Wil Sinclair (wil) on 2008-09-02T10:39:41.000+0000
Updating for the 1.6.0 release.
Have you found an issue?
See the Overview section for more details.