note 48362 added to function.setcookie

From: Date: Mon, 20 Dec 2004 22:13:43 +0000
Subject: note 48362 added to function.setcookie
Groups: php.notes 
Request: Send a blank email to php-notes+get-82101@lists.php.net to get a copy of this message
s4t4n at mailinator dot com: > > ie. something like > > > > if($_POST["foo"]) { > > $bar = $_POST["foo"]; > > } else { > > $bar = $_COOKIE["foo"]; > > } > > Why oh why such code when something like the following is a) more readable b) shorter! > > $bar = $_POST["foo"] or $_COOKIE["foo"]; because c) that doesn't work ! $_POST["foo"]=NULL; $_COOKIE["foo"]="doh"; $bar=$_POST["foo"] or $_COOKIE["foo"]; echo $bar; and you won't see "doh" as you would with the if statement above. However, this IS quicker and easier and works: $bar = ($_POST["foo"]?$_POST["foo"]:$_COOKIE["foo"]); ---- Manual Page -- http://www.php.net/manual/en/function.setcookie.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+48362 Delete -- http://master.php.net/manage/user-notes.php?action=delete+48362&report=yes Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+48362&report=yes&reason=bad+code Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+48362&report=yes&reason=spam Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+48362&report=yes&reason=useless+example Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+48362&report=yes&reason=contains+commercial+links Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+48362&report=yes&reason=useless+note Reject -- http://master.php.net/manage/user-notes.php?action=reject+48362&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#82101) next »