3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php // DBLogger.php class DBLogger { private $enabled; private $operations; private $ignoredTables; public function __construct() { $this->enabled = false; $this->operations = null; $this->ignoredTables = null; } public function enable() { $this->enabled = true; return $this; } public function disable() { $this->enabled = false; return $this; } public function operations($operations) { $this->operations = $operations; return $this; } public function ignoreTables($tables) { $this->ignoredTables = $tables; return $this; } public function log($query) { if(!$this->enabled) return; $queryParts = explode(" ", $query); $queryCommand = $queryParts[0]; if($this->operations === null || strripos($this->operations, $queryCommand) !== false) { $tables = $this->ignoredTables === null ? array() : explode(",", $this->ignoredTables); $numOfTables = count($tables); for($i=0; $i<$numOfTables; $i++) { $tableName = str_replace(" ", "", $tables[$i]); if(strpos($query, $tableName) !== false) { return; } } $file = "queries_".date("Y-d-m").".sql"; $this->writeToFile($file, $query); } return $this; } private function writeToFile($file, $query) { $dir = dirname(__FILE__)."/logs/"; $content = ''; if(file_exists($dir.$file)) { $content = file_get_contents($dir.$file)."\n\n"; } $content .= $query.";"; file_put_contents($dir.$file, $content); } } global $dblogger; $dblogger = new DBLogger();
Output for 5.0.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/WhMjQ on line 7
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/WhMjQ on line 7
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/WhMjQ on line 7
Process exited with code 255.