note 69022 added to language.operators

From: Date: Sun, 20 Aug 2006 05:30:56 +0000
Subject: note 69022 added to language.operators
Groups: php.notes 
Request: Send a blank email to php-notes+get-116078@lists.php.net to get a copy of this message
In response to 26-Mar-2001 08:53, parens don't need to have precedence. There's only one way to convert them to a syntax tree. I can't think of a sensible reason it could be ambiguous either (and sensible language designers will make ( always pair with ) so there can't be any ambiguity). In response to 12-Aug-2005 08:47, you can do <?php $myvar OR ($myvar = 1); ?>, or the equivalent <?php !$myvar AND $myvar = 1; ?>, and if you have to use ifs, <?php if(!$myvar) { $myvar = 1; } ?> will do just fine (though in general, I'd be careful using boolean expressions as an indicator of success/failure when 0 could be a valid value. And you probably want to use isset($myvariable)). In response to the manual, associativity doesn't determine the order of evaluation - it determines how it's "bracketed": a=b=c=1 is equivalent to a=(b=(c=1)), but a is evaluated first (an important point if evaluating a has side-effects) <?php function one($str) { echo "$str"; return 1; } $a = array(1,2); $a[one("A")] = $a[one("B")] = 1; // outputs AB ?> ---- Server IP: 85.116.0.130 Probable Submitter: 82.71.54.164 ---- X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/language.operators.php Edit -- https://master.php.net/note/edit/69022 Del: integrated -- https://master.php.net/note/delete/69022/integrated Del: useless -- https://master.php.net/note/delete/69022/useless Del: bad code -- https://master.php.net/note/delete/69022/bad+code Del: spam -- https://master.php.net/note/delete/69022/spam Del: non-english -- https://master.php.net/note/delete/69022/non-english Del: in docs -- https://master.php.net/note/delete/69022/in+docs Del: other reasons-- https://master.php.net/note/delete/69022 Reject -- https://master.php.net/note/reject/69022 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#116078) next »