note 38034 added to language.operators.logical

From: Date: Fri, 05 Dec 2003 13:40:01 +0000
Subject: note 38034 added to language.operators.logical
Groups: php.notes 
Request: Send a blank email to php-notes+get-61447@lists.php.net to get a copy of this message
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 |. ---- Manual Page -- http://www.php.net/manual/en/language.operators.logical.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+38034 Delete -- http://master.php.net/manage/user-notes.php?action=delete+38034&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+38034&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#61447) next »