3v4l.org

run code in 300+ PHP versions simultaneously
<?php // Outside of the application, e.g. DB, RPC or some storage. function addSomeIntegerFieldToDB($value) { $sql = 'INSERT INTO mytable (integer_field) VALUES (:int)'; // $st = $pdo->prepare($sql); // $st->execute(array('int' => $value); echo "executing query: ".str_replace(':int', $value, $sql)." \n"; } // the application: global $conditional; global $withAssert; class X { public function doSmth($id) { global $conditional; global $withAssert; if ($withAssert) { // Assertion will run outside of the if/else below // Preventing a wrong $id to be passed to ->doSmth() method, independent of the $conditional assert(is_int($id), new \InvalidArgumentException('wot ar y doin')); } if ($conditional) { addSomeIntegerFieldToDB($id); } } } $obj = new X; $withAssert = false; $conditional = true; // Assert off, conditional on $obj->doSmth(13); $obj->doSmth('x'); // Assert off, conditional off $conditional = false; $obj->doSmth(13); $obj->doSmth('x'); // Assert on, conditional on $withAssert = true; $conditional = true; $obj->doSmth(13); $obj->doSmth('x'); // Assert on, conditional off $conditional = false; $obj->doSmth(13); $obj->doSmth('x');
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
executing query: INSERT INTO mytable (integer_field) VALUES (13) executing query: INSERT INTO mytable (integer_field) VALUES (x) executing query: INSERT INTO mytable (integer_field) VALUES (13) Fatal error: Uncaught InvalidArgumentException: wot ar y doin in /in/oLsu2:25 Stack trace: #0 /in/oLsu2(57): X->doSmth('x') #1 {main} thrown in /in/oLsu2 on line 25
Process exited with code 255.
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 executing query: INSERT INTO mytable (integer_field) VALUES (13) executing query: INSERT INTO mytable (integer_field) VALUES (x) executing query: INSERT INTO mytable (integer_field) VALUES (13) Fatal error: Uncaught InvalidArgumentException: wot ar y doin in /in/oLsu2:25 Stack trace: #0 /in/oLsu2(57): X->doSmth('x') #1 {main} thrown in /in/oLsu2 on line 25
Process exited with code 255.
Output for 7.0.0 - 7.0.20, 7.1.0 - 7.1.20, 7.2.5 - 7.2.33, 7.3.16 - 7.3.33, 7.4.0 - 7.4.33
executing query: INSERT INTO mytable (integer_field) VALUES (13) executing query: INSERT INTO mytable (integer_field) VALUES (x) executing query: INSERT INTO mytable (integer_field) VALUES (13) Warning: assert(): InvalidArgumentException: wot ar y doin in /in/oLsu2:25 Stack trace: #0 /in/oLsu2(57): X->doSmth('x') #1 {main} failed in /in/oLsu2 on line 25 executing query: INSERT INTO mytable (integer_field) VALUES (x) Warning: assert(): InvalidArgumentException: wot ar y doin in /in/oLsu2:25 Stack trace: #0 /in/oLsu2(63): X->doSmth('x') #1 {main} failed in /in/oLsu2 on line 25
Output for 5.5.0 - 5.5.38, 5.6.0 - 5.6.28
executing query: INSERT INTO mytable (integer_field) VALUES (13) executing query: INSERT INTO mytable (integer_field) VALUES (x) executing query: INSERT INTO mytable (integer_field) VALUES (13) Warning: assert(): exception 'InvalidArgumentException' with message 'wot ar y doin' in /in/oLsu2:25 Stack trace: #0 /in/oLsu2(57): X->doSmth('x') #1 {main} failed in /in/oLsu2 on line 25 executing query: INSERT INTO mytable (integer_field) VALUES (x) Warning: assert(): exception 'InvalidArgumentException' with message 'wot ar y doin' in /in/oLsu2:25 Stack trace: #0 /in/oLsu2(63): X->doSmth('x') #1 {main} failed in /in/oLsu2 on line 25

preferences:
190.5 ms | 403 KiB | 224 Q