3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $pdo = new pdo('sqlite::memory:', null, null, [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]); $pdo->exec('create table foo(id int primary key, letter text)'); $ids = insert($pdo, 'insert into foo(letter) values(?), (?), (?)', ['a', 'b', 'c']); var_dump($ids, $pdo->query('select * from foo')->fetchAll(PDO::FETCH_ASSOC)); function insert($pdo, string $sql, array $params = []) : array { if (stripos($sql, 'INSERT') !== 0) { throw new InvalidArgumentException('##LG_NOT_AN_INSERT_STATEMENT##'); } //$pdo = $this->getAdapter()->getConnection(); $stmt = $pdo->prepare($sql); $stmt->execute($params); $count = $stmt->rowCount(); $last = $pdo->lastInsertId(); return range($last - $count, $last); }
Output for 7.0.0 - 7.3.0beta1
array(4) { [0]=> int(0) [1]=> int(1) [2]=> int(2) [3]=> int(3) } array(3) { [0]=> array(2) { ["id"]=> NULL ["letter"]=> string(1) "a" } [1]=> array(2) { ["id"]=> NULL ["letter"]=> string(1) "b" } [2]=> array(2) { ["id"]=> NULL ["letter"]=> string(1) "c" } }
Output for hhvm-3.15.4
Fatal error: Uncaught exception 'Exception' with message '__construct() expects parameter 2 to be string, null given' in /in/eLHO8:3 Stack trace: #0 /in/eLHO8(3): PDO->__construct() #1 {main}
Process exited with code 255.
Output for 5.6.0 - 5.6.30
Parse error: syntax error, unexpected ':', expecting '{' in /in/eLHO8 on line 10
Process exited with code 255.