Bug Report #3551
Error with cookies in Response::send_headers()
| Status: | Closed | Start date: | 01/07/2011 | |
|---|---|---|---|---|
| Priority: | Normal | Due date: | ||
| Assignee: | % Done: | 0% |
||
| Category: | Core | |||
| Target version: | v3.1.4 | |||
| Resolution: | fixed | Points: |
Description
send_headers() expects cookie to be an array of value and expiration, but only string value can be set. I think, Response::cookie() should be extended with third param like 'lifetime'.
Associated revisions
Refs #3551, fixes the cookie interface in Response to use compatible interface to Cookie class
Refs #3551, removed the incorrect variable - damn over coffee brain
History
Updated by Sam de Freyssinet over 2 years ago
- Status changed from New to Needs Test
- Resolution set to fixed
Updated by Dmitry T. over 2 years ago
Sam, what is $fruit here?
https://github.com/kohana/core/blob/705d5fc5d95af4ce466dc37f46d5ec902a18c4b4/classes/kohana/response.php#L350
And why not use foreach instead of while?
Updated by Jeremy Bush over 2 years ago
list/while is faster than foreach().
Updated by Dmitry T. over 2 years ago
Jeremy, I see, thanks for the reply.
Nevertheless
while (list($_key, $_value) = each($fruit))should be
while (list($_key, $_value) = each($key))Shouldn't it?
Updated by Jeremy Bush over 2 years ago
Probably :)
Updated by Isaiah DeRose-Wilson over 2 years ago
Jeremy Bush wrote:
list/while is faster than foreach().
Actually I don't think that's true. I haven't benchmarked it in a while, but last time I looked foreach() was actually faster (compared to using a while/list/each/reset combination). It does depend on what you do with the array in the foreach/loop, but most of the time foreach will be faster. However, the difference is normally so small it really doesn't matter though. I normally use foreach() for this kind of stuff because I find it easier to use.
Updated by Jeremy Bush over 2 years ago
Sorry, I didn't mean faster. it uses less memory in some situations where a foreach() would consume more memory and not let it go.
I used to have a link about it, but I seem to have lost it.
Anyway, this isn't the place for this debate :)
Updated by Dmitry T. over 2 years ago
I agree with Isaiah. IMO code readability is more important than speed (futhermore when spped gain is doubtful), so I suggest change to foreach
Updated by Steven G. over 2 years ago
Isaiah DeRose-Wilson wrote:
Jeremy Bush wrote:
list/while is faster than foreach().
Actually I don't think that's true. I haven't benchmarked it in a while, but last time I looked foreach() was actually faster (compared to using a while/list/each/reset combination).
foreach is better every time if it's a iteration over all elements
The so called benchmarks that supposedly prove otherwise I found most use very pointless tests such as empty bodies or operations that don't really access data (ie. make use of the loop). Each time I would benchmark against a real world example and not some cute code, foreach would come out on top. I am not sure (bad memory) if this was one of them, but at one point PHP devs have come forward to debunk a lot of these so called "better coding" practices, a lot of which had become so widespread google even had them as "recommended practices".
Anyway, foreach should be favored, if nothing else, because of readability.
Jeremy Bush wrote:
Sorry, I didn't mean faster. it uses less memory in some situations where a foreach() would consume more memory and not let it go.
Do you mean as in "foreach consumes more memory"? Last time I researched into this, I found if you have speed or memory problems in the loop consider using a more specialized data type (not that array is bad). See: http://matthewturland.com/2010/05/20/new-spl-features-in-php-5-3/ for some charts.
Or do you mean "foreach is bugged"? Do you have some kind of code that produces this? Or some bug report of this being a memory leak? Does this happen when you write:
foreach ($list as &$value)or only when you write
foreach ($list as $value)
Updated by Sam de Freyssinet over 2 years ago
The reason for while/each in this instance is because each() produces such a horrible interface for the foreach loop. I personally believe in this instance, the syntax used is easier to read that foreach - therefore it will remain. The incorrect variable splurge however has been amended ;) apologies for that obvious error.
Updated by Jeremy Bush over 2 years ago
Please keep this discussion on topic.
Updated by Kiall Mac Innes over 2 years ago
- Target version changed from v3.1.0 to v3.1.1
Updated by Jeremy Bush over 2 years ago
- Target version changed from v3.1.1 to v3.1.2
Updated by Jeremy Bush about 2 years ago
- Target version changed from v3.1.2 to v3.1.3
Updated by Jeremy Bush about 2 years ago
- Target version changed from v3.1.3 to v3.1.4
Updated by Sam de Freyssinet almost 2 years ago
- Status changed from Needs Test to Closed