Use "AND" "OR" instead of "&&" "||" #47230
-
This idea came to my mind that using logical operators "AND" "OR" can help the readability of the code Exp: protected function shouldIgnore($name)
{
return str_starts_with($name, '__') ||
in_array($name, $this->ignoredMethods());
} Use protected function shouldIgnore($name)
{
return str_starts_with($name, '__') OR
in_array($name, $this->ignoredMethods()); // Maybe it's better to change the code style!
} |
Beta Was this translation helpful? Give feedback.
Answered by
faissaloux
May 26, 2023
Replies: 2 comments
-
In PHP |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
nunomaduro
-
From https://www.php.net/manual/en/language.operators.logical.php : // "||" has a greater precedence than "or"
// The result of the expression (false || true) is assigned to $e
// Acts like: ($e = (false || true))
$e = false || true;
// The constant false is assigned to $f before the "or" operation occurs
// Acts like: (($f = false) or true)
$f = false or true;
// --------------------
// "&&" has a greater precedence than "and"
// The result of the expression (true && false) is assigned to $g
// Acts like: ($g = (true && false))
$g = true && false;
// The constant true is assigned to $h before the "and" operation occurs
// Acts like: (($h = true) and false)
$h = true and false; |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In PHP
AND
doesn't work like&&
, same forOR
doesn't work like||