RE: Re: UNLESS Statement Equivalent

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



-----Original Message-----
From: Ford, Mike [mailto:M.Ford@xxxxxxxxxxxxxx] 
Sent: 12 March 2013 10:51 AM
To: PHP General
Subject: RE:  Re: UNLESS Statement Equivalent

> unless ( $a and $b )
> =
> if ( ! ($a and $b) )
> 
> So in simple terms, just stick a ! (or the keyword not) in front of 
> your expression, and you'll have exactly what you want:
> if( not ( ($current_page == $saved_page) and ($current_ip ==
> $saved_ip)
> and ($current_dt < ($saved_dt + 3600) ) ) {

Whilst this is true as far as it goes, I would suggest applying deMorgan's
laws to simplify slightly to

   if ( ($current_page != $saved_page) or ($current_ip != $saved_ip) or
($current_dt >= ($saved_dt + 3600) ) )

Also, the keyword versions of the Boolean operators are very low priority,
which is why you need all those extra parentheses -- if you switch to the
symbolic versions, you can leave all the internal parentheses out to give:

   if ($current_page != $saved_page || $current_ip != $saved_ip ||
$current_dt >= $saved_dt + 3600)

Cheers!
Mike
--

Mike, I presume you're saying the precedence of the Boolean keyword
operators is lower than the Boolean symbol operators, but if so then
wouldn't there be less need for the parentheses? I prefer using the Boolean
keyword operators for both the readability and because of the lower
precedence. Unless I've been wrong all this while and the keyword precedence
is actually higher?

Cheers
Arno


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux