Bug #63286 [NEW]: in_array returns false on the $_COOKIE array when the cookie name exists
From: pascal at niele dot nl
Operating system: debian
PHP version: Irrelevant
Package: Arrays related
Bug Type: Bug
Bug description:in_array returns false on the $_COOKIE array when the cookie name exists
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 bug report at https://bugs.php.net/bug.php?id=63286&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=63286&r=trysnapshot54
Try a snapshot (PHP 5.3): https://bugs.php.net/fix.php?id=63286&r=trysnapshot53
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=63286&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=63286&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=63286&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=63286&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=63286&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=63286&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=63286&r=support
Expected behavior: https://bugs.php.net/fix.php?id=63286&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=63286&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=63286&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=63286&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=63286&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=63286&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=63286&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=63286&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=63286&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=63286&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=63286&r=mysqlcfg
Thread (2 messages)
- pascal at niele dot nl