|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #63286 in_array returns false on the $_COOKIE array when the cookie name exists
Submitted: 2012-10-16 08:32 UTC Modified: 2012-10-16 09:23 UTC
From: pascal at niele dot nl Assigned:
Status: Not a bug Package: Arrays related
PHP Version: Irrelevant OS: debian
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: pascal at niele dot nl
New email:
PHP Version: OS:


 [2012-10-16 08:32 UTC] pascal at niele dot nl
From manual page:

The in_array($cookieName, $_COOKIE) always returns false even if the $cookieName exists in the $_COOKIE array

Test script:
When checking if a cookie exist, the in_array() does not work on the $_COOKIE array, you should isset() to check if the cookie exists.

 * part 1, setting cookie
$name = 'testCookie';
$value = 'testValue';
$expires = time() + (60 * 60 * 24 * 365);
$path = '/';

setcookie($name, $value, $expires, $path);

 * part 2, retrieving cookie
// output: array(1) { ["testCookie"] => string(9) "testValue" }

// output: bool(true)

var_dump(in_array($name, $_COOKIE)); // does not work as aspected !!!
// ouput: bool(false)

echo $_COOKIE[$name];
// output: testValue

Expected result:
return true on the in_array($cookieName, $_COOKIE) if the $cookieName exists in the $_COOKIE array


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2012-10-16 09:23 UTC]
-Status: Open +Status: Not a bug
 [2012-10-16 09:23 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

in_array is searching a value, not a key.
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sun Jan 17 04:01:23 2021 UTC