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); } else { echo "Skipping a query with value of '".$id."'\n"; } } } $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 off $withAssert = true; $conditional = false; $obj->doSmth(13); $obj->doSmth('x'); // Assert on, conditional on $conditional = true; $obj->doSmth(13); $obj->doSmth('x');
Output for git.master, git.master_jit, rfc.property-hooks
executing query: INSERT INTO mytable (integer_field) VALUES (13) executing query: INSERT INTO mytable (integer_field) VALUES (x) Skipping a query with value of '13' Skipping a query with value of 'x' Skipping a query with value of '13' Fatal error: Uncaught InvalidArgumentException: wot ar y doin in /in/kNd0Y:25 Stack trace: #0 /in/kNd0Y(60): X->doSmth('x') #1 {main} thrown in /in/kNd0Y on line 25
Process exited with code 255.

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
82.04 ms | 401 KiB | 8 Q