3v4l.org

run code in 500+ PHP versions simultaneously
<?php declare(strict_types=1); // print() ignores strict_types... print (1 + 2) * 3; // outputs "9"; the parentheses cause 1+2 to be evaluated first, then 3*3 // the print statement sees the whole expression as one argument // As for the type mismatch? the strict_types ? ignored.. echo "\n"; if ( print("hello") and false ) { print "WTF: inside if"; } else { print "OK: inside else"; } echo "\n"; if ( 1 && false ) { print "WTF: inside if"; } else { print "OK: inside else"; } echo "\n"; print "hello " and print "world"; // outputs "world1"; ... WTF? echo "\n"; ob_start(); print "hello " and print "world"; $str = ob_get_clean(); assert(str_contains($str, 'hello'));
Output for 8.0.30, 8.1.0 - 8.1.34, 8.2.0 - 8.2.30, 8.3.0 - 8.3.31, 8.4.1 - 8.4.22, 8.5.0 - 8.5.7
9 helloOK: inside else OK: inside else hello world
Output for 7.0.33, 7.2.34
9 helloOK: inside else OK: inside else hello world Fatal error: Uncaught Error: Call to undefined function str_contains() in /in/G2ihX:36 Stack trace: #0 {main} thrown in /in/G2ihX on line 36
Process exited with code 255.
Output for 5.6.40
Warning: Unsupported declare 'strict_types' in /in/G2ihX on line 2 9 helloOK: inside else OK: inside else hello world Fatal error: Call to undefined function str_contains() in /in/G2ihX on line 36
Process exited with code 255.
Output for 5.1.6, 5.2.17
9 helloOK: inside else OK: inside else hello world Fatal error: Call to undefined function str_contains() in /in/G2ihX on line 36
Process exited with code 255.

preferences:
57.17 ms | 1032 KiB | 4 Q