note 38034 deleted from language.operators.logical by didou

From: Date: Fri, 05 Dec 2003 13:42:06 +0000
Subject: note 38034 deleted from language.operators.logical by didou
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-61449@lists.php.net to get a copy of this message
Note Submitter: ---- Those that have spent time with Perl or Ruby might burn themselves on this idiom: $id = $_POST['id'] or $_GET['id']; Nice little shortcut, that's actually makes sense, even if it might confuse the first time. Well, it doesn't work in PHP, as the logical operators evaluate to a boolean value, not to the 'winning' value. This works though: $id = $_POST['id'] or $id = $_GET['id']; even if it is a bit more verboose, it makes sense. braintrino: It doesn't 'assume' that short-cirvuiting is best, you're *telling* it that you want it. || is an extension to |.

« previous php.notes (#61449) next »