1

I have this code:

if ( ($oldTime < (time() - self::wait)) ) {
  if ($this->setTime())
  {
    return true;
  }
  else
  {
    return false;
  }
} else {
  return false;
}

Can i replace it with:

if ( ($oTime < (time() - self::wait)) && $this->setTime() ) {
  return true;
} else {
  return false;
}

I need it to check if $this->setTime() returns true ONLY if $oTime < (time() - self::wait) is true.

2
  • 1
    Yes you can, this is the same. Commented Mar 12, 2013 at 19:56
  • 1
    Offtopic Dude, we've got the same avatar... Respect my authority! :-D Commented Mar 12, 2013 at 20:04

3 Answers 3

6
return ($oTime < (time() - self::wait)) && $this->setTime()
Sign up to request clarification or add additional context in comments.

2 Comments

So i can to the replacement right? and if $oTime < (time() - self::wait) is false, $this->setTime() will not be executed?
Yes, if I am understanding you correctly. && is a short-circuiting operator, so if the first condition is false, the second condition will not execute.
1

yes you can use this

if ( ($oTime < (time() - self::wait)) && $this->setTime() ) {
        return true;
    } else {
        return false;
    }

Comments

1

if first condition in the if statement with && ( not || ) fails, it will go to the else branch automatically without verifying the second condition

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.