Edit report at https://bugs.php.net/bug.php?id=63286&edit=1

 ID:                 63286
 Updated by:         larue...@php.net
 Reported by:        pascal at niele dot nl
 Summary:            in_array returns false on the $_COOKIE array when
                     the cookie name exists
-Status:             Open
+Status:             Not a bug
 Type:               Bug
 Package:            Arrays related
 Operating System:   debian
 PHP Version:        Irrelevant
 Block user comment: N
 Private report:     N

 New Comment:

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.


Previous Comments:
------------------------------------------------------------------------
[2012-10-16 08:32:35] 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



------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=63286&edit=1

Reply via email to