Jump to content

Am I Tired? Please help


bitagenda

Recommended Posts

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

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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)

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.