3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php namespace SQLQuery; class SQLQuery { private static $methods = array('select', 'update', 'drop', 'delete', 'create', 'alter', 'set'); private static $char_list = array( 'default' => array( 'escape' => '\\', 'quotes' => '"', 'names' => '`', 'name_separator' => '.' ), 'mysqli' => array( 'escape' => '\\', 'quotes' => '"', 'names' => '`', 'name_separator' => '.' ), 'sqlite3' => array( 'escape' => '\\', 'quotes' => '"', 'names' => '`', 'name_separator' => '.' ) ); private $chars = array(); private $type = 'unknown'; private $link = null; function __call($method, $arguments){ if(!in_array($method, self::$methods)) { throw new BadMethodCallException('Method ' . $method . ' does not exist'); } $class = __CLASS__ . ucfirst($method); return new $class($this, $this->chars, $arguments); } function __construct($link = false){ if(is_resource($link)) { $type = get_resource_type($link); if($type !== 'mysql link' || $type !== 'mysql link persistent') { throw new InvalidArgumentException('MySQL resource expected, ' . $type . ' given'); } $this->link = $link; $this->type = 'mysql'; $this->chars = self::$char_list['default']; } else if(is_object($link)) { if(class_exists('PDO') && ($link instanceof \PDO)) { $type = $link->getAttribute(\PDO::ATTR_DRIVER_NAME); } else if(class_exists('mysqli') && ($link instanceof \mysqli)) { $type = 'mysqli'; } else if(class_exists('SQLite3') && ($link instanceof \SQLite3)) { $type = 'sqlite3'; } else { throw new InvalidArgumentException('Unsupported connection type ' . get_class($link)); } $this->link = $link; $this->type = $type; $this->chars = self::$char_list[$type]; } else throw new InvalidArgumentException('Resource or Object excepted, ' . gettype($link) . ' given'); } } if(!@class_alias('SQLQuery\\SQLQuery', '\\SQLQuery')) { // very ugly hack eval('class SQLQuery extends \SQLQuery\SQLQuery{};'); } final class SQLQuerySelect { function __construct(SQLQuery $sql, array $chars, $arguments){ var_dump($chars, $arguments); } } // --------------------------------- $x = new \SQLQuery(new \SQLite3()); $x->select('a');
based on IdAVJ
Output for 7.1.0 - 7.2.6
Fatal error: Uncaught ArgumentCountError: SQLite3::__construct() expects at least 1 parameter, 0 given in /in/6rgvb:97 Stack trace: #0 /in/6rgvb(97): SQLite3->__construct() #1 {main} thrown in /in/6rgvb on line 97
Process exited with code 255.
Output for 7.0.0 - 7.0.23
Fatal error: Uncaught TypeError: SQLite3::__construct() expects at least 1 parameter, 0 given in /in/6rgvb:97 Stack trace: #0 /in/6rgvb(97): SQLite3->__construct() #1 {main} thrown in /in/6rgvb on line 97
Process exited with code 255.
Output for hhvm-3.18.4 - 3.21.0
Fatal error: Uncaught exception 'Exception' with message 'SQLite3::__construct() expects at least 1 parameter, 0 given' in /in/6rgvb:97 Stack trace: #0 /in/6rgvb(97): SQLite3->__construct() #1 {main}
Process exited with code 255.
Output for 5.6.0 - 5.6.30
Fatal error: Uncaught exception 'Exception' with message 'SQLite3::__construct() expects at least 1 parameter, 0 given' in /in/6rgvb:97 Stack trace: #0 /in/6rgvb(97): SQLite3->__construct() #1 {main} thrown in /in/6rgvb on line 97
Process exited with code 255.