Run Rector on your code to see what it can do for you:

 <?php
 
 # Ternary operator, left.
-(true ? 42 : 0) and true; # -> true
+true ? 42 : 0 && true; # -> true
 
 # Ternary operator, right.
-true and (true ? 42 : 0); # -> true
+true && true ? 42 : 0; # -> true
 
 # Elvis operator, left.
 $x = 42;
-($x ?: 0) and true; # -> true
+$x ?: 0 && true; # -> true
 
 # Elvis operator, right.
 $x = 0;
-true and ($x ?: 42); # -> true
+true && $x ?: 42; # -> true
 
 # Combined assignment operator, left.
 $x = 0;
-($x += 42) and true; # -> true, and $x is 42
+$x += 42 && true; # -> true, and $x is 42
 
 # Combined assignment operator, middle.
 $x = 0;
-true and ($x += 42) and true; # -> true, and $x is 42
+true && $x += 42 && true; # -> true, and $x is 42
 
 # 'print', left.
-(print "foo") and (print "bar"); # -> true, prints "foobar"
+print "foo" && print "bar"; # -> true, prints "foobar"
 
 # 'print', middle.
-true and (print "foo") or (print "bar"); # -> true, prints "foo"
+true && print "foo" || print "bar"; # -> true, prints "foo"
 
 # 'yield', left.
-(yield "foo") or (yield "bar"); # -> false, yields "foo" then "bar"
+yield "foo" || yield "bar"; # -> false, yields "foo" then "bar"
 
 # 'yield', middle.
-true and (yield "foo") or (yield "bar"); # -> false, yields "foo" then "bar"
+true && yield "foo" || yield "bar"; # -> false, yields "foo" then "bar"
 
 # 'yield from', left.
-(yield from ["foo"]) or (yield from ["bar"]); # -> false, yields "foo" then "bar"
+yield from ["foo"] || yield from ["bar"]; # -> false, yields "foo" then "bar"
 
 # 'yield from', middle.
-true and (yield from ["foo"]) or (yield from ["bar"]); # -> false, yields "foo" then "bar"
+true && yield from ["foo"] || yield from ["bar"]; # -> false, yields "foo" then "bar"
PHP snippet to change

Applied Rules:

Not a change you expect?

Config  rector.php
Rector version: 2.5.4 - released at 2026-07-05 23:08