3v4l.org

run code in 300+ PHP versions simultaneously
<?php abstract class Model { /** * Tabela representativa. * @var [array] */ private $_Table; /** * Meta-Descrições dos Campos. * @var [array] */ protected $_Meta; /** * Listagem dos Campos. * @var [array] */ protected $_Fields; /** * Listagem de Campos que não são podem ser Nulos. * @var [array] */ protected $_NotNull; /** * Instância de banco de dados Singleton. * @var [PDO] */ protected static $db; /** * Listagem de todas as instâncias. * @var [array][array] */ private static $_Cache; public static function _Instance() { self::$db = new db(); } /** * Define a tabela que será usada no objeto. * @param [string] $table Tabela representativa. */ private function setTable($table) { # Verifica se a entrada é válida. if(empty($table)) throw new Exception("A tabela não pode ser vazia."); # Define a tabela na classe. $this->_Table = $table; } public function Insert() { try { Validate::Run($this); foreach($this->_Fields as $Field) $binds[':' . $Field] = $this->{$Field}; $values = implode(', ', keys($binds)); $fields = $this->_Fields; unset($fields[0]); $fields = implode(', ', $this->_Fields); $query = "INSERT INTO ". $this->_Table ."(". $fields .") VALUES(". $values .")"; self::e($query, $binds); $this->Select(self::$db->lastInsertId()); } catch(Exception $e) { echo $e->getMessage(); return false; } } public function Select($id = NULL) { if(is_null($id)) { $id = $this->{$this->_Fields[0]}; if(is_null($id)) throw new Exception("Impossível realizar select com id nulo da tabela ". $this->_Table ."."); } $fields = implode(', ', $this->_Fields); $query = "SELECT ". $fields ." FROM ". $this->_Table ." WHERE ". $this->_Fields[0] ." = ?"; $stmt = self::e($query , array($id)); $row = $stmt->fetch(PDO::FETCH_ASSOC); if($row) { $this->_ResetFields(); foreach($this->_Fields as $Field) $this->{$Field} = $row[$Field]); # $this->{'Hash'} = Bcrypt::hash($id . $this->_Table); self::$_Cache[$this->_Table][$this->_Fields[0]] = $this; } else throw new Exception("Id ". $id ." não existe na tabela ". $this->_Table); } public function Delete($id = NULL) { if(is_null($id)) { $id = $this->{$this->_Fields[0]}; if(is_null($id)) throw new Exception("Impossível deletar um id nulo da tabela ". $this->_Table ."."); } $query = "SELECT ". $fields ." FROM ". $this->_Table ." WHERE ". $this->_Fields[0] ." = ?"; $stmt = self::e($query , array($id)); if($stmt->fetch()) { if(Db::VirtualDeletion['on']) { $query = "UPDATE ". $this->_Table ." SET ". Db::VirtualDeletion['Field'] ." = '". Db:VirtualDeletion['Value'] ."' WHERE ". $this->_Fields[0] ." = ?"; self::e($query, array($id)); } else { $query = "DELETE FROM ". $this->_Table ." WHERE ". $this->_Fields[0] ." = ?"; self::e($query, array($id)); } return true; } else throw new Exception("O id ". $id ." não pode ser excluído da tabela ". $this->_Table ." pois não existe."); } public function Update($id = NULL) { if(is_null($id)) { $id = $this->{$this->_Fields[0]}; if(is_null($id)) throw new Exception("Impossível realizer update em um id nulo da tabela ". $this->_Table ."."); } Validate::Run($this); foreach($this->_Fields as $Field) $binds[':' . $Field] = $this->{$Field}; $fields = $this->_Fields; unset($fields[0]); foreach($fields as $Field) $values[] = $Field .' = '. $this->{$Field}; $values[] = implode(', ', $values); $query = "UPDATE ". $this->_Table ." SET ". $values ." WHERE ". $this->_Fields[0] ." = :" . $this->_Fields[0]; self::e($query, $binds); unset( self::$_Cache[$this->_Table][$this->_Fields[0]] ); $this->Select($id); } /** * Limpa os objetos da memória cache. */ public static function Clear() { unset(self::$_Cache); } protected static function e($query, $binds) { $_stmt = self::$db->prepare($query); $_stmt->execute($binds); return $_stmt; } protected static function q($query) { return self::$db->query($query); } public function __destruct() { self::$db = null; unset(self::$_Cache); } } ?>

Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).

VersionSystem time (s)User time (s)Memory (MiB)
5.5.80.0200.07319.22
5.5.70.0230.07719.28
5.5.60.0300.07319.38
5.5.50.0130.05319.45
5.5.40.0230.07319.38
5.5.30.0130.04719.33
5.5.20.0230.08019.37
5.5.10.0430.06319.49
5.5.00.0170.05719.25
5.4.240.0300.04019.11
5.4.230.0200.04018.92
5.4.220.0400.06318.95
5.4.210.0170.04319.13
5.4.200.0300.06018.86
5.4.190.0300.06318.92
5.4.180.0200.04019.14
5.4.170.0100.05019.14
5.4.160.0270.05018.98
5.4.150.0330.05319.00
5.4.140.0270.04716.38
5.4.130.0270.06316.45
5.4.120.0200.07316.25
5.4.110.0230.06716.39
5.4.100.0300.06016.39
5.4.90.0230.07016.43
5.4.80.0200.07316.46
5.4.70.0170.06716.46
5.4.60.0170.05716.41
5.4.50.0270.03716.43
5.4.40.0330.05716.38
5.4.30.0230.07016.38
5.4.20.0230.06716.38
5.4.10.0230.04716.27
5.4.00.0170.03715.77
5.3.280.0330.06014.50
5.3.270.0230.07314.63
5.3.260.0130.05014.63
5.3.250.0230.07714.55
5.3.240.0130.07314.69
5.3.230.0230.04714.62
5.3.220.0170.07714.58
5.3.210.0230.07314.64
5.3.200.0300.07014.64
5.3.190.0270.07714.59
5.3.180.0170.04014.60
5.3.170.0270.07314.47
5.3.160.0300.06714.60
5.3.150.0330.05714.73
5.3.140.0300.05714.73
5.3.130.0300.08014.57
5.3.120.0200.07714.57
5.3.110.0230.06014.58
5.3.100.0230.07314.06
5.3.90.0230.05014.20
5.3.80.0170.05314.18
5.3.70.0330.04714.00
5.3.60.0270.06314.07
5.3.50.0300.06714.11
5.3.40.0230.06713.95
5.3.30.0300.05713.93
5.3.20.0230.05013.74
5.3.10.0330.06013.67
5.3.00.0300.05013.80

preferences:
135.48 ms | 1394 KiB | 7 Q