douglaswalker Posted July 3, 2018 Share Posted July 3, 2018 Hi there, I have come across a curious coding issue which may just be curious to me... but I wondered if any\one has come across it and could shed any light. Ok here goes.... the code below works as expected and stops the code running on checkout_shipping.php, checkout_payment.php and checkout_confirmation.php function isEnabled() { global $PHP_SELF; if (($PHP_SELF == 'checkout_shipping.php')|| ($PHP_SELF == 'checkout_payment.php') || ($PHP_SELF == 'checkout_confirmation.php')) { $this->enabled = false; } return $this->enabled; } Then i tried the code below to allow the code to run on checkout_shipping.php, checkout_payment.php and checkout_confirmation.php but no where else however it does not work and the code runs nowhere. function isEnabled() { global $PHP_SELF; if (($PHP_SELF != 'checkout_shipping.php')|| ($PHP_SELF != 'checkout_payment.php') || ($PHP_SELF != 'checkout_confirmation.php')) { $this->enabled = false; } return $this->enabled; } then I tried this (see below and it works perfectly. Only allowing the code to run on checkout_shipping.php, checkout_payment.php and checkout_confirmation.php function isEnabled() { global $PHP_SELF; if (($PHP_SELF != 'checkout_shipping.php')&& ($PHP_SELF != 'checkout_payment.php') && ($PHP_SELF != 'checkout_confirmation.php')) { $this->enabled = false; } return $this->enabled; } I thought that if I added && then all the conditions had to be correct at the same time? Why does the || not work? Any light that can be shed would be appreciated Link to comment Share on other sites More sharing options...
Hotclutch Posted July 3, 2018 Share Posted July 3, 2018 If you want to use || this logic will suffice: function isEnabled() { global $PHP_SELF; if (($PHP_SELF == 'checkout_shipping.php') || ($PHP_SELF == 'checkout_payment.php') || ($PHP_SELF == 'checkout_confirmation.php')) { return $this->enabled; } } Link to comment Share on other sites More sharing options...
douglaswalker Posted July 3, 2018 Author Share Posted July 3, 2018 Oh my god.. I am stupid thank-you Link to comment Share on other sites More sharing options...
burt Posted July 3, 2018 Share Posted July 3, 2018 Keep it more simple and allow the possibility to easier add pages in; $pages = array('checkout_shipping.php', 'checkout_payment.php', 'checkout_confirmation.php'); if (!in_array($PHP_SELF, $pages)) { // is NOT a page in $pages } if (in_array($PHP_SELF, $pages)) { // IS a page in $pages } G Link to comment Share on other sites More sharing options...
douglaswalker Posted July 3, 2018 Author Share Posted July 3, 2018 nice... thank-you Link to comment Share on other sites More sharing options...
MrPhil Posted July 3, 2018 Share Posted July 3, 2018 Basic Boolean logic: not(A or B) is the same as (not A) and (not B). Likewise not(A and B) is the same as (not A) or (not B). By the way, == and != are higher precedence than || or &&, so the inner () can safely be omitted. Some coders prefer to explicitly give them just so things are perfectly clear to the next reader. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.