Bug Report #3551

Error with cookies in Response::send_headers()

Added by Ivan Brotkin almost 4 years ago. Updated over 3 years ago.

Status:ClosedStart date:01/07/2011
Priority:NormalDue date:
Assignee:Sam de Freyssinet% 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

Revision 705d5fc5
Added by Sam de Freyssinet almost 4 years ago

Refs #3551, fixes the cookie interface in Response to use compatible interface to Cookie class

Revision 6a3a6275
Added by Sam de Freyssinet almost 4 years ago

Refs #3551, removed the incorrect variable - damn over coffee brain

History

#1 Updated by Sam de Freyssinet almost 4 years ago

  • Status changed from New to Needs Test
  • Resolution set to fixed

#3 Updated by Jeremy Bush almost 4 years ago

list/while is faster than foreach().

#4 Updated by Dmitry T. almost 4 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?

#5 Updated by Jeremy Bush almost 4 years ago

Probably :)

#6 Updated by Isaiah DeRose-Wilson almost 4 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.

#7 Updated by Jeremy Bush almost 4 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 :)

#8 Updated by Dmitry T. almost 4 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

#9 Updated by Steven G. almost 4 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)

#10 Updated by Sam de Freyssinet almost 4 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.

#11 Updated by Jeremy Bush almost 4 years ago

Please keep this discussion on topic.

#12 Updated by Kiall Mac Innes almost 4 years ago

  • Target version changed from v3.1.0 to v3.1.1

#13 Updated by Jeremy Bush almost 4 years ago

  • Target version changed from v3.1.1 to v3.1.2

#14 Updated by Jeremy Bush almost 4 years ago

  • Target version changed from v3.1.2 to v3.1.3

#15 Updated by Jeremy Bush over 3 years ago

  • Target version changed from v3.1.3 to v3.1.4

#16 Updated by Sam de Freyssinet over 3 years ago

  • Status changed from Needs Test to Closed

Also available in: Atom PDF