#21569 [Com]: PHP can't set cookies after a test with an unset variable

From: Date: Mon, 13 Jan 2003 16:48:18 +0000
Subject: #21569 [Com]: PHP can't set cookies after a test with an unset variable
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-29878@lists.php.net to get a copy of this message
ID: 21569 Comment by: ElfQrin@ElfQrin.com Reported By: ElfQrin@ElfQrin.com Status: Bogus Bug Type: Unknown/Other Function Operating System: Windows 2000 only PHP Version: 4.3.0 New Comment: Workaround #2: At the beginning og your script, "declare" any possibly unset variable that will be invoked: if (!isset($test)) {$test="";} Previous Comments: ------------------------------------------------------------------------ [2003-01-13 10:07:12] ElfQrin@ElfQrin.com Workaround (which doesn't mean this bug shouldn't be fixed): To perform tests: if (!isset($test) || $test=="") { echo ""; } To set a variable: $a=""; if (isset($test)) { $a=$test; } ------------------------------------------------------------------------ [2003-01-13 10:05:53] ElfQrin@ElfQrin.com I've found out that the problem is not limited to tests. It happens every time you invoke an unset variable before than setting a cookie. In the previous example, try $a = $test; instead of if ($test=="") { echo ""; } and the setcookie won't work as well. ------------------------------------------------------------------------ [2003-01-13 10:03:29] ElfQrin@ElfQrin.com This is a shortest example: <? # $test=""; setcookie("debug","1",0,"",""); if ($test=="") { echo ""; } setcookie("debug","3",0,"",""); echo "Cookie: [".$_COOKIE["debug"]."] (HIT RELOAD)<BR>"; ?> ------------------------------------------------------------------------ [2003-01-10 13:14:02] ElfQrin@ElfQrin.com I've submitted a specific bug. It depends either from PHP or Windows 2000 itself in some way, because I've tested it deeply in many configurations of operating systems, Apache and PHP versions. The sample code provided is a proof of concept, not a code I'm asking advice about. ------------------------------------------------------------------------ [2003-01-10 12:56:40] sniper@php.net Sorry, but your problem does not imply a bug in PHP itself. For a list of more appropriate places to ask for help using PHP, please visit http://www.php.net/support.php as this bug system is not the appropriate forum for asking support questions. Thank you for your interest in PHP. ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at http://bugs.php.net/21569 -- Edit this bug report at http://bugs.php.net/?id=21569&edit=1

« previous php.bugs (#29878) next »