Symfony\Component\HttpFoundation\ResponseHeaderBag::removeCookie PHP Method

removeCookie() public method

Removes a cookie from the array, but does not unset it in the browser.
public removeCookie ( string $name, string $path = '/', string $domain = null )
$name string
$path string
$domain string
    public function removeCookie($name, $path = '/', $domain = null)
    {
        if (null === $path) {
            $path = '/';
        }

        unset($this->cookies[$domain][$path][$name]);

        if (empty($this->cookies[$domain][$path])) {
            unset($this->cookies[$domain][$path]);

            if (empty($this->cookies[$domain])) {
                unset($this->cookies[$domain]);
            }
        }

        if (empty($this->cookies)) {
            unset($this->headerNames['set-cookie']);
        }
    }

Usage Example

 public function testRemoveCookie()
 {
     $bag = new ResponseHeaderBag();
     $bag->setCookie(new Cookie('foo', 'bar', 0, '/path/foo', 'foo.bar'));
     $bag->setCookie(new Cookie('bar', 'foo', 0, '/path/bar', 'foo.bar'));
     $cookies = $bag->getCookies(ResponseHeaderBag::COOKIES_ARRAY);
     $this->assertTrue(isset($cookies['foo.bar']['/path/foo']));
     $bag->removeCookie('foo', '/path/foo', 'foo.bar');
     $cookies = $bag->getCookies(ResponseHeaderBag::COOKIES_ARRAY);
     $this->assertFalse(isset($cookies['foo.bar']['/path/foo']));
     $bag->removeCookie('bar', '/path/bar', 'foo.bar');
     $cookies = $bag->getCookies(ResponseHeaderBag::COOKIES_ARRAY);
     $this->assertFalse(isset($cookies['foo.bar']));
 }
All Usage Examples Of Symfony\Component\HttpFoundation\ResponseHeaderBag::removeCookie