note 124035 added to language.operators

From: Date: Sat, 13 Jul 2019 08:55:55 +0000
Subject: note 124035 added to language.operators
Groups: php.notes 
Request: Send a blank email to php-notes+get-211552@lists.php.net to get a copy of this message
If you use "AND" and "OR", you'll eventually get tripped up by something like this: <?php $this_one = true; $that = false; $truthiness = $this_one and $that; ?> Want to guess what $truthiness equals? If you said "false" ...it's wrong! "$truthiness" above has the value "true". Why? "=" has a higher precedence than "and". The addition of parentheses to show the implicit order makes this clearer: <?php ($truthiness = $this_one) and $that; ?> If you used "&&" instead of and in the first code example, it would work as expected and be "false". This also works to get the correct value, as parentheses have higher precedence than "=": <?php $truthiness = ($this_one and $that); ?> ---- Server IP: 208.43.231.9 Probable Submitter: 185.85.3.195 (proxied: 78.30.154.70) ---- Manual Page -- http://php.net/manual/en/language.operators.php Edit -- https://master.php.net/note/edit/124035 Del: integrated -- https://master.php.net/note/delete/124035/integrated Del: useless -- https://master.php.net/note/delete/124035/useless Del: bad code -- https://master.php.net/note/delete/124035/bad+code Del: spam -- https://master.php.net/note/delete/124035/spam Del: non-english -- https://master.php.net/note/delete/124035/non-english Del: in docs -- https://master.php.net/note/delete/124035/in+docs Del: other reasons-- https://master.php.net/note/delete/124035 Reject -- https://master.php.net/note/reject/124035 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#211552) next »