3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Database { protected static $instance; protected $pdo; protected $lastExecute; 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->pdo->query($sql); } if ($stmt = $this->pdo->prepare($sql)) { $this->lastExecute = $stmt->execute($args); } return $stmt; } /** * @return null|bool */ public function getLastExecute() { return $this->lastExecute; } 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(); $db->run('SELECT ?', ['foo', 'bar']); var_dump($db->getLastExecute()); //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/UbM1N:32 Stack trace: #0 /in/UbM1N(32): PDOStatement->execute(Array) #1 /in/UbM1N(61): Database->run('SELECT ?', Array) #2 {main} thrown in /in/UbM1N on line 32
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:
50.18 ms | 401 KiB | 8 Q