Re: setcookie() minor BC break - fixes issue #67736

From: Date: Sun, 02 Nov 2014 10:24:20 +0000
Subject: Re: setcookie() minor BC break - fixes issue #67736
References: 1 2 3 4 5 6 7 8 9 10  Groups: php.internals 
Request: Send a blank email to internals+get-78558@lists.php.net to get a copy of this message
> On 02 11 2014, at 01:33, Rowan Collins <rowan.collins@gmail.com> wrote: > > On 01/11/2014 22:24, Andrea Faulds wrote: >> Perhaps it would be worth ditching any attempts to change setcookie() (just keep it around >> for backwards-compatibility), and to instead add a new function, function family, or indeed class >> for cookie handling. Some sort of sane API which would allow you to do a, b, or c, and make it clear >> which you wanted. >> >> Thoughts? Any idea what such an API might look like? > > That rather brings us back to this week's Hot Topic: HTTP response objects, pecl/http, and > PSR-7. > > pecl/httpv2 has the http\Cookie class [1], which confusingly represents not a single cookie, > but a whole set of cookies. Exactly how you attach this to a response is not really clear from the > docs I can find. > It it’s confusing, the docs are not good enough, and I probably have to agree here ;) Anyway, http\Cookie can parse Cookie and Set-Cookie headers, though, looking at the RFC that might have been a bad idea to implement it that way. Cookies never have been a main area of interest to me, so there might be a lot of room to improve in pecl/http. Obviously, API for cookies is completely missing in the http\Env sub namespace, probably because there was $_COOKIE and set_cookie(), which may have covered my needs for it. Setting a cookie currently would mean just setting the appropriate Set-Cookie header on an http\Env\Response instance. - - - 8< - - - $ php -r '$r = new http\Env\Response; \ $r->setHeader("Set-Cookie", \ ((new http\Cookie("foo=bar"))->setExpires(strtotime("+1 day")))); \ $r->send(STDOUT);’ HTTP/1.1 200 OK Set-Cookie: foo=bar; expires=Mon, 03 Nov 2014 10:21:43 GMT; ETag: "" - - - >8 - - - > [1] http://devel-m6w6.rhcloud.com/mdref/http/Cookie > <http://devel-m6w6.rhcloud.com/mdref/http/Cookie> Cheers, Mike

« previous php.internals (#78558) next »