note 46666 added to language.operators.comparison

From: Date: Tue, 19 Oct 2004 18:05:58 +0000
Subject: note 46666 added to language.operators.comparison
Groups: php.notes 
Request: Send a blank email to php-notes+get-78777@lists.php.net to get a copy of this message
if you want to use the ?: operator, you should be careful with the precedence. Here's an example of the priority of operators: echo 'Hello, ' . isset($i) ? 'my friend: ' . $username . ', how are you doing?' : 'my guest, ' . $guestusername . ', please register'; This make "'Hello, ' . isset($i)" the sentence to evaluate. So, if you think to mix more sentences with the ?: operator, please use always parentheses to force the proper evaluation of the sentence. echo 'Hello, ' . (isset($i) ? 'my friend: ' . $username . ', how are you doing?' : 'my guest, ' . $guestusername . ', please register'); for general rule, if you mix ?: with other sentences, always close it with parentheses. ---- Manual Page -- http://www.php.net/manual/en/language.operators.comparison.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+46666 Delete -- http://master.php.net/manage/user-notes.php?action=delete+46666&report=yes Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+46666&report=yes&reason=bad+code Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+46666&report=yes&reason=spam Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+46666&report=yes&reason=useless+example Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+46666&report=yes&reason=contains+commercial+links Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+46666&report=yes&reason=useless+note Reject -- http://master.php.net/manage/user-notes.php?action=reject+46666&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#78777) next »