3v4l.org

run code in 300+ PHP versions simultaneously
<?php // Outside of the application, e.g. DB 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; class X { public function doSmth($id) { // Assertion will run independently of $conditional, thus preventing a wrong $id to be passed to ->doSmth() method assert(is_int($id), new \InvalidArgumentException('wot ar y doin')); global $conditional; if ($conditional) { addSomeIntegerFieldToDB($id); } } } $conditional = true; $obj = new X; $obj->doSmth(13); $obj->doSmth('x'); $obj->doSmth(000001234000); $conditional = false; $obj->doSmth(13); $obj->doSmth('x'); $obj->doSmth(000001234000);
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.6
executing query: INSERT INTO mytable (integer_field) VALUES (13) Fatal error: Uncaught InvalidArgumentException: wot ar y doin in /in/1MM8P:20 Stack trace: #0 /in/1MM8P(36): X->doSmth('x') #1 {main} thrown in /in/1MM8P on line 20
Process exited with code 255.
Output for 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33
executing query: INSERT INTO mytable (integer_field) VALUES (13) Warning: assert(): InvalidArgumentException: wot ar y doin in /in/1MM8P:20 Stack trace: #0 /in/1MM8P(36): X->doSmth('x') #1 {main} failed in /in/1MM8P on line 20 executing query: INSERT INTO mytable (integer_field) VALUES (x) executing query: INSERT INTO mytable (integer_field) VALUES (342016) Warning: assert(): InvalidArgumentException: wot ar y doin in /in/1MM8P:20 Stack trace: #0 /in/1MM8P(42): X->doSmth('x') #1 {main} failed in /in/1MM8P on line 20
Output for 5.5.0 - 5.5.38, 5.6.0 - 5.6.40
executing query: INSERT INTO mytable (integer_field) VALUES (13) Warning: assert(): exception 'InvalidArgumentException' with message 'wot ar y doin' in /in/1MM8P:20 Stack trace: #0 /in/1MM8P(36): X->doSmth('x') #1 {main} failed in /in/1MM8P on line 20 executing query: INSERT INTO mytable (integer_field) VALUES (x) executing query: INSERT INTO mytable (integer_field) VALUES (342016) Warning: assert(): exception 'InvalidArgumentException' with message 'wot ar y doin' in /in/1MM8P:20 Stack trace: #0 /in/1MM8P(42): X->doSmth('x') #1 {main} failed in /in/1MM8P on line 20

preferences:
198.69 ms | 403 KiB | 327 Q