RE: [PHP] Re: UNLESS Statement Equivalent
-Original Message- From: Maciek Sokolewicz [mailto:tula...@gmail.com] On Behalf Of Maciek Sokolewicz Sent: 11 March 2013 22:44 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 Ford, Electronic Information Developer, Libraries and Learning Innovation, Portland PD507, City Campus, Leeds Metropolitan University, Portland Way, LEEDS, LS1 3HE, United Kingdom E: m.f...@leedsmet.ac.uk T: +44 113 812 4730 To view the terms under which this email is distributed, please go to http://disclaimer.leedsmet.ac.uk/email.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: UNLESS Statement Equivalent
2013/3/12 Ford, Mike m.f...@leedsmet.ac.uk -Original Message- From: Maciek Sokolewicz [mailto:tula...@gmail.com] On Behalf Of Maciek Sokolewicz Sent: 11 March 2013 22:44 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) ) ) If it is simpler depends, because not ($everything $must $be $true) is sometimes more logical :) 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) Just to throw that in if (array($current_page, $current_ip, $current_dt) != array($saved_page, $saved_ip, $saved_dt + 3600)) This at least includes the information, that you have to sets of values, that should be equal :) Cheers! Mike -- Mike Ford, Electronic Information Developer, Libraries and Learning Innovation, Portland PD507, City Campus, Leeds Metropolitan University, Portland Way, LEEDS, LS1 3HE, United Kingdom E: m.f...@leedsmet.ac.uk T: +44 113 812 4730 To view the terms under which this email is distributed, please go to http://disclaimer.leedsmet.ac.uk/email.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- github.com/KingCrunch
RE: [PHP] Re: UNLESS Statement Equivalent
-Original Message- From: Ford, Mike [mailto:m.f...@leedsmet.ac.uk] Sent: 12 March 2013 10:51 AM To: PHP General Subject: RE: [PHP] 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
RE: [PHP] Re: UNLESS Statement Equivalent
-Original Message- From: Ford, Mike [mailto:m.f...@leedsmet.ac.uk] Sent: 12 March 2013 10:51 AM To: PHP General Subject: RE: [PHP] 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 -- I checked the manual, the Boolean symbol operators have a higher precedence than ternary and assignment, while the Boolean keyword operators have the lowest precedence. So using Boolean keyword operators should obviate internal parentheses. Cheers Arno -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Re: UNLESS Statement Equivalent
-Original Message- From: Arno Kuhl [mailto:a...@dotcontent.net] Sent: 12 March 2013 13:04 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? You are absolutely right, of course -- I failed to engage brain before typing words! Both sets of Boolean operators have lower priority than the comparison operators, so none of the parentheses are needed in either of those cases -- it's the assigning operators (and ?:) that come between the symbolic and keyword Booleans, so that $a = $b = true$c means something different from $a = $b=true and $c Thanks for picking me up on that one! Cheers! Mike -- Mike Ford, Electronic Information Developer, Libraries and Learning Innovation, Portland PD507, City Campus, Leeds Metropolitan University, Portland Way, LEEDS, LS1 3HE, United Kingdom E: m.f...@leedsmet.ac.uk T: +44 113 812 4730 To view the terms under which this email is distributed, please go to http://disclaimer.leedsmet.ac.uk/email.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php