Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:78559 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 52591 invoked from network); 2 Nov 2014 13:44:07 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 2 Nov 2014 13:44:07 -0000 Authentication-Results: pb1.pair.com header.from=danack@basereality.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=danack@basereality.com; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain basereality.com from 74.125.82.52 cause and error) X-PHP-List-Original-Sender: danack@basereality.com X-Host-Fingerprint: 74.125.82.52 mail-wg0-f52.google.com Received: from [74.125.82.52] ([74.125.82.52:54855] helo=mail-wg0-f52.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 8C/A3-13276-32536545 for ; Sun, 02 Nov 2014 08:44:04 -0500 Received: by mail-wg0-f52.google.com with SMTP id b13so8752334wgh.25 for ; Sun, 02 Nov 2014 05:44:00 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=6Iprl6hJXq1LRvkTe8Oets8wUSLXvGcpGGou9IJSZV0=; b=U6MVPSAfOR93Amsp8nqjOGrxdd1oaLkk3MQxuNU2/1pDm06Xn/r8mmje5ewRyVHmtS aWk//jjapA23auviltdhGNKG6LYP5hH9Pq+GV9t2YewfONmxPxYxAyM336tiDEqRkC2c dcAkB+lWYae/TS/zsFlwXlHMTsixYMdZ8olMxa8RGrN47TaI2I61qzGvO8girRLiNmjp VO16/oZ7+NRx+GhlwNeMvUkjeanhFIKok61qXIq82V2btZHygSZQ/FuBhwwvHsm6G97t 3jLABlLXRipSe/dGtA8ozuU2NIRkbOuoCxS1CJn+FsOzP0aJgkxY//JQjNoeR5+xi0uo PLhQ== X-Gm-Message-State: ALoCoQnZqUqTUXiwyrH5z8sqMkiMXRczqgS3MYt8W4jTvpdhR9+WP9Y5Eq5Rj8jARJJbf8Gq+YLp MIME-Version: 1.0 X-Received: by 10.194.185.115 with SMTP id fb19mr1046811wjc.121.1414935839937; Sun, 02 Nov 2014 05:43:59 -0800 (PST) Received: by 10.216.11.70 with HTTP; Sun, 2 Nov 2014 05:43:59 -0800 (PST) X-Originating-IP: [2.99.239.194] In-Reply-To: References: Date: Sun, 2 Nov 2014 13:43:59 +0000 Message-ID: To: Florian Margaine Cc: Chris Wright , Ferenc Kovacs , Sherif Ramadan , Tjerk Meesters , PHP Internals Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] setcookie() minor BC break - fixes issue #67736 From: danack@basereality.com (Dan Ackroyd) Florian wrote: > On the PR of the setcookie pat= ch > to become compliant with the HTTP RFC, >There are some facts: > >- the current way does not follow the HTTP RFC. Please stop saying this, it isn't true. From rfc6265: > Servers SHOULD NOT include more than one Set-Cookie header field in the s= ame response with the same cookie-name.: From rfc2119: > SHOULD NOT This phrase, or the phrase "NOT RECOMMENDED" mean that > there may exist valid reasons in particular circumstances when the > particular behavior is acceptable or even useful, but the full > implications should be understood and the case carefully weighed > before implementing any behavior described with this label.: The behaviour of PHP is ABSOLUTELY in compliance with the RFC 6265. Setting two headers may not follow best practice but it is conformant, and it is only doing what the users PHP script told it to do. The problem that you're actually trying to address is that for most people, they didn't mean to send two cookie headers twice and only did it because they have a bug in their code, with the same header being sent twice: setcookie('foo', 'bar1'); setcookie('foo', 'bar2'); The correct way to fix this is not to introduce a new function that alters global state; the correct way to it is for the user to just fix the bug in their code, and only call setcookie once: $fooCookie =3D 'bar1'; $fooCookie =3D 'bar2'; setcookie('foo', $fooCookie); Adding a new function just to allow people to work round a bug in their code sounds nuts. > we cannot have the "last come last served" cookie because it's a BC break= . Just to reiterate, it would also be incorrect behaviour. Setting is multiple cookies with the same name is allowed, just not recommended. I think the generating a warning on setting a duplicate header is an ok idea. That would help most people (who presumably didn't mean to do that) but be slightly annoying for people who have an existing application that deliberately uses multiple setcookie with the same name, as they would need to add error suppression. cheers Dan On 1 November 2014 17:09, Florian Margaine wrote: > Hi list, > > On the PR of the setcookie pat= ch > to become compliant with the HTTP RFC, a valid use case for not throwing = a > warning when running setcookie() twice with the same name: deleting cooki= es > (setcookie('name', '', ...);). It's thus been proposed to add an > unsetcookie() method. > > I'm not set on whether it's a good thing or not. I'm also not sure how to > handle this. > > There are some facts: > > - the current way does not follow the HTTP RFC. > - we cannot have the "last come last served" cookie because it's a BC bre= ak. > - the current functions cannot allow us to unset a cookie. > > What should be done? Trying to keep BC at a minimum by adding an > unsetcookie() method and add warnings? Try to detect the deletion of > cookies (empty value) and add warnings to keep even more BC? > > I'm unsure on what should be done and would like internals' opinion :-) > > On Tue, Sep 9, 2014 at 4:53 PM, Chris Wright wrote: > >> On 8 September 2014 09:09, Ferenc Kovacs wrote: >> > On Mon, Sep 8, 2014 at 9:15 AM, Sherif Ramadan >> > wrote: >> > >> >> Actually, we shouldn't be doing that all. We should simply just >> overwrite >> >> the header. It wouldn't make much sense to set two headers with the s= ame >> >> cookie name when we can just overwrite it. >> >> >> >> >> >> >> > that would be a bigger BC break, and without a warning, those people >> > affected by the change will have a harder time figuring out what went >> wrong. >> > and as was discussed both in the PR and the bugreport the rfc discoura= ges >> > but doesn't prohibit this behavior, so making it impossible for the >> > userland to do it would be a bit of an arbitrary restriction. >> > maybe we could do something like introducing a new $overwrite =3D true >> option >> > to the function signature, but setcookie already has 7 arguments, so >> > probably isn't a great idea. >> >> -- >> > Ferenc Kov=C3=A1cs >> > @Tyr43l - http://tyrael.hu >> > > Regards, > > -- > Florian Margaine