3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Database { protected static $instance; protected $pdo; protected function __construct() { $this->pdo = new PDO('sqlite::memory:'); } public static function instance() { if (null === self::$instance) { self::$instance = new self; } return self::$instance; } /** * @return PDOStatement|false */ public function run($sql, $args = []) { if (!$args) { return $this->query($sql); } if ($stmt = $this->prepare($sql)) { if ($stmt->execute($args)) { return $stmt; } } return false; } public function __call($method, $args) { if (is_callable([$this->pdo, $method])) { //php 5.6+ variadic optimization (aka splat operator) return $this->pdo->$method(...$args); //PHP <= 5.5 //return call_user_func_array(array($this->pdo, $method), $args); } throw new \BadMethodCallException(sprintf('Unknown method PDO::%s called!', $method)); } } //RunTime code $db = Database::instance(); var_dump($db->run('SELECT ?', ['foo', 'bar'])); //false
Output for git.master, git.master_jit, rfc.property-hooks
Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 25 column index out of range in /in/OnDdn:31 Stack trace: #0 /in/OnDdn(31): PDOStatement->execute(Array) #1 /in/OnDdn(54): Database->run('SELECT ?', Array) #2 {main} thrown in /in/OnDdn on line 31
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:
18.47 ms | 401 KiB | 8 Q