3v4l.org

run code in 300+ PHP versions simultaneously
<?php function test_case($a, $b, $c) { // Without Parenthesis if ($a || $b && $c) { $test1 = TRUE; } else { $test1 = FALSE; } // With Parenthesis if (($a || $b) && $c) { $test2 = TRUE; } else { $test2 = FALSE; } // Compare result if ($test1 !== $test2) { printf( 'Condition (%s || %s && %s) does NOT match ((%s || %s) && %s) --- Should have been "%s" but was actually "%s"'.PHP_EOL, strtoupper(var_export($a, TRUE)), strtoupper(var_export($b, TRUE)), strtoupper(var_export($c, TRUE)), strtoupper(var_export($a, TRUE)), strtoupper(var_export($b, TRUE)), strtoupper(var_export($c, TRUE)), strtoupper(var_export($test2, TRUE)), strtoupper(var_export($test1, TRUE)) ); } else { printf( 'Condition (%s || %s && %s) works as intended'.PHP_EOL, strtoupper(var_export($a, TRUE)), strtoupper(var_export($b, TRUE)), strtoupper(var_export($c, TRUE)) ); } } // Test all possible variations test_case(TRUE, TRUE, TRUE); test_case(TRUE, TRUE, FALSE); test_case(TRUE, FALSE, TRUE); test_case(TRUE, FALSE, FALSE); test_case(FALSE, TRUE, TRUE); test_case(FALSE, TRUE, FALSE); test_case(FALSE, FALSE, TRUE); test_case(FALSE, FALSE, FALSE);
Output for 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.19, 8.3.0 - 8.3.4, 8.3.6 - 8.3.7
Condition (TRUE || TRUE && TRUE) works as intended Condition (TRUE || TRUE && FALSE) does NOT match ((TRUE || TRUE) && FALSE) --- Should have been "FALSE" but was actually "TRUE" Condition (TRUE || FALSE && TRUE) works as intended Condition (TRUE || FALSE && FALSE) does NOT match ((TRUE || FALSE) && FALSE) --- Should have been "FALSE" but was actually "TRUE" Condition (FALSE || TRUE && TRUE) works as intended Condition (FALSE || TRUE && FALSE) works as intended Condition (FALSE || FALSE && TRUE) works as intended Condition (FALSE || FALSE && FALSE) works as intended
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 Condition (TRUE || TRUE && TRUE) works as intended Condition (TRUE || TRUE && FALSE) does NOT match ((TRUE || TRUE) && FALSE) --- Should have been "FALSE" but was actually "TRUE" Condition (TRUE || FALSE && TRUE) works as intended Condition (TRUE || FALSE && FALSE) does NOT match ((TRUE || FALSE) && FALSE) --- Should have been "FALSE" but was actually "TRUE" Condition (FALSE || TRUE && TRUE) works as intended Condition (FALSE || TRUE && FALSE) works as intended Condition (FALSE || FALSE && TRUE) works as intended Condition (FALSE || FALSE && FALSE) works as intended

preferences:
140.28 ms | 403 KiB | 214 Q