php.net |  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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: pascal at niele dot nl
New email:
PHP Version: OS:

 

 [2012-10-16 08:32 UTC] pascal at niele dot nl
Description:
------------
---
From manual page: http://www.php.net/function.setcookie
---

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

Test script:
---------------
Note: 
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.

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

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


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

var_dump(isset($_COOKIE[$name]));
// 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


Patches

Pull Requests

History

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

http://us.php.net/manual/en/function.in-array.php

in_array is searching a value, not a key.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Mon Jul 14 20:01:55 2025 UTC