bitagenda Posted February 24, 2007 Share Posted February 24, 2007 Just a question the PHP operators && as and are the same? I do understand Yes they are, only with different precedence. so Why? $dat = true and true; // results in true // OK $dat = true and false // results in true????????? shouldn't it be false? $dat = true && true // results in true // OK $dat = true && false // results in false // OK Done a test with each combination ... $dat = $dat?'yes';'no'; echo $dat; myKey: ofdl Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 24, 2007 Share Posted February 24, 2007 Can you show the actual code, because what you've posted doesn't make much sense... Quote Link to comment Share on other sites More sharing options...
bitagenda Posted February 24, 2007 Author Share Posted February 24, 2007 Can you show the actual code, because what you've posted doesn't make much sense... I did not write the code, because it is a long function but it is something like this $secure = isset($_SESSION['login']) and ($_SESSION['login']['loginuser']==$SiteAdmin or $_SESSION['login']['loginuser']==$SiteMaster); I did ckeck value by value, for example they were true and (false or false); Surprisse!! results in true??? So I did a small test, the one posted $secure = true and (false or false) Zas the same result then $secure = true and false Zas the same result of true then $secure = true && false the results is ok So please, help me what I do not understand? Is it a bug? to me the result of true and false should be as FALSE as true && false Thanks Quote Link to comment Share on other sites More sharing options...
bitagenda Posted February 24, 2007 Author Share Posted February 24, 2007 Can you show the actual code, because what you've posted doesn't make much sense... jesirose ... help me please Look $a = true; $b=false; $secure = $a and $b; $res = $secure?'yes':'not'; echo $res; Why the response is 'yes'? Quote Link to comment Share on other sites More sharing options...
utexas_pjm Posted February 24, 2007 Share Posted February 24, 2007 Order of operations. Here: <?php $a = true; $b=false; $secure = ($a and $b); $res = $secure?'yes':'not'; echo $res; ?> Best, Patrick Quote Link to comment Share on other sites More sharing options...
bitagenda Posted February 24, 2007 Author Share Posted February 24, 2007 Order of operations. Here: <?php $a = true; $b=false; $secure = ($a and $b); $res = $secure?'yes':'not'; echo $res; ?> Best, Patrick RIGHT PATRICK !!!! I am tired, no doubt about it. Just if others read about this ... take care with an error like this. The reason the result is TRUE With NO parenthesis PHP assigns first $secure = $a, which is true, so it will remain true. $secure = $a and $b; then PHP does 'and b' with result in false but assigned to nothing. so to get the right answer $secure = ($a and $b) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.