Closed Gsinti closed 4 years ago
This is helpful in order to reduce boilerplate code as I'm currently calling the unset() function myself after every call to the delete() function in the \Delight\Cookie\Cookie class.
Thank you for your feedback and the pull request!
You are right about this. But just the same is true for the Cookie#save
method, isn’t it?
So while you’d like to have Cookie#delete
also unset the $_COOKIE
variable in the same request, I might like to have Cookie#save
create the variable inside $_COOKIE
right away.
Do you agree?
So instead of this breaking change, what about two additional methods, Cookie#saveAndSet
and Cookie#deleteAndUnset
?
Good point about the save
method lacking this functionality! It too would benefit from being set immediately so that it is available in PHP memory before headers are sent.
I like the idea of two additional methods that can serve this purpose.
Thanks again, @Gsinti!
Implemented in https://github.com/delight-im/PHP-Cookie/commit/103ce742d964457d03edadb3276aead28a36505f and https://github.com/delight-im/PHP-Cookie/commit/83c30014b35b9f690841f879fa77d72a51d94d52
By the way, a minor correction, @Gsinti, the question is not “before headers are sent” vs. “after headers have been sent”. Instead, it’s “before the next line in the script (in the current HTTP request)” vs. “at the start of the next HTTP request”.
You're welcome!
I wasn't sure about the exact terminology and I appreciate the lesson in semantics. Thanks for the clarification!
Unset the cookie name in PHP's $_COOKIE variable to prevent it being referenced before headers can be sent.