3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php class Filter { protected $pattern; protected $repl; function __construct($pattern, $repl) { $this->pattern = $pattern; $this->repl = $repl; } function filter($data) { return preg_replace($this->pattern, $this->repl, $data); } function __destruct(){ echo "BYE BITCH\n"; } }; class Post { protected $title; protected $text; protected $filters; function __construct($title, $text, $filters) { $this->title = $title; $this->text = $text; $this->filters = $filters; } function get_title() { return htmlspecialchars($this->title); } function display_post() { $text = htmlspecialchars($this->text); foreach ($this->filters as $filter) $text = $filter->filter($text); return $text; } function __destruct() { // debugging stuff $s = "<!-- POST " . htmlspecialchars($this->title); $text = htmlspecialchars($this->text); echo 'WOAH ITS A FILTER '.'"'.$this->filters.'"'; foreach ($this->filters as $filter) $text = $filter->filter($text); $s = $s . ": " . $text; $s = $s . " -->"; echo $s; } }; $standard_filter_set = [new Filter("/\[i\](.*)\[\/i\]/i", "<i>\\1</i>"), new Filter("/\[b\](.*)\[\/b\]/i", "<b>\\1</b>"), new Filter("/\[img\](.*)\[\/img\]/i", "<img src='\\1'>"), new Filter("/\[br\]/i", "<br>")]; echo serialize(new Post("hue", "br", [new Filter("/gibe/", "gibe moni"), new Filter("/moni/", "i repor u")])); unserialize('O:4:"Post":3:{s:8:"*title";s:3:"hue";s:7:"*text";s:2:"br";s:10:"*filters";a:2:{i:0;O:6:"Filter":2:{s:10:"*pattern";s:6:"/gibe/";s:7:"*repl";s:9:"gibe moni";}i:1;O:6:"Filter":2:{s:10:"*pattern";s:6:"/moni/";s:7:"*repl";s:9:"i repor u";}}}');
based on JF2mG
Output for 7.1.0
Notice: Array to string conversion in /in/7PPJI on line 43 WOAH ITS A FILTER "Array"<!-- POST hue: br -->BYE BITCH BYE BITCH O:4:"Post":3:{s:8:"*title";s:3:"hue";s:7:"*text";s:2:"br";s:10:"*filters";a:2:{i:0;O:6:"Filter":2:{s:10:"*pattern";s:6:"/gibe/";s:7:"*repl";s:9:"gibe moni";}i:1;O:6:"Filter":2:{s:10:"*pattern";s:6:"/moni/";s:7:"*repl";s:9:"i repor u";}}} Notice: unserialize(): Error at offset 27 of 237 bytes in /in/7PPJI on line 58 WOAH ITS A FILTER "" Warning: Invalid argument supplied for foreach() in /in/7PPJI on line 44 <!-- POST : -->BYE BITCH BYE BITCH BYE BITCH BYE BITCH
Output for 5.4.0 - 5.6.24, 7.0.0 - 7.0.14
Notice: Array to string conversion in /in/7PPJI on line 43 WOAH ITS A FILTER "Array"<!-- POST hue: br -->BYE BITCH BYE BITCH O:4:"Post":3:{s:8:"*title";s:3:"hue";s:7:"*text";s:2:"br";s:10:"*filters";a:2:{i:0;O:6:"Filter":2:{s:10:"*pattern";s:6:"/gibe/";s:7:"*repl";s:9:"gibe moni";}i:1;O:6:"Filter":2:{s:10:"*pattern";s:6:"/moni/";s:7:"*repl";s:9:"i repor u";}}}WOAH ITS A FILTER "" Warning: Invalid argument supplied for foreach() in /in/7PPJI on line 44 <!-- POST : --> Notice: unserialize(): Error at offset 27 of 237 bytes in /in/7PPJI on line 58 BYE BITCH BYE BITCH BYE BITCH BYE BITCH
Output for hhvm-3.12.0 - 3.13.2
Notice: Array to string conversion in /in/7PPJI on line 43 WOAH ITS A FILTER "Array"<!-- POST hue: br -->BYE BITCH BYE BITCH O:4:"Post":3:{s:8:"*title";s:3:"hue";s:7:"*text";s:2:"br";s:10:"*filters";a:2:{i:0;O:6:"Filter":2:{s:10:"*pattern";s:6:"/gibe/";s:7:"*repl";s:9:"gibe moni";}i:1;O:6:"Filter":2:{s:10:"*pattern";s:6:"/moni/";s:7:"*repl";s:9:"i repor u";}}} Warning: htmlspecialchars() expects parameter 1 to be string, null given in /in/7PPJI on line 41 Warning: htmlspecialchars() expects parameter 1 to be string, null given in /in/7PPJI on line 42 WOAH ITS A FILTER "" Warning: Invalid argument supplied for foreach() in /in/7PPJI on line 45 <!-- POST : --> Notice: Unable to unserialize: [O:4:"Post":3:{s:8:"*title";s:3:"hue";s:7:"*text";s:2:"br";s:10:"*filters";a:2:{i:0;O:6:"Filter":2:{s:10:"*pattern";s:6:"/gibe/";s:7:"*repl";s:9:"gibe moni";}i:1;O:6:"Filter":2:{s:10:"*pattern";s:6:"/moni/";s:7:"*repl";s:9:"i repor u";}}}]. Expected '"' but got 's'. in /in/7PPJI on line 58 BYE BITCH BYE BITCH BYE BITCH BYE BITCH
Output for hhvm-3.10.0
Notice: Array to string conversion in /in/7PPJI on line 43 WOAH ITS A FILTER "Array"<!-- POST hue: br -->BYE BITCH BYE BITCH O:4:"Post":3:{s:8:"*title";s:3:"hue";s:7:"*text";s:2:"br";s:10:"*filters";a:2:{i:0;O:6:"Filter":2:{s:10:"*pattern";s:6:"/gibe/";s:7:"*repl";s:9:"gibe moni";}i:1;O:6:"Filter":2:{s:10:"*pattern";s:6:"/moni/";s:7:"*repl";s:9:"i repor u";}}}WOAH ITS A FILTER "" Warning: Invalid argument supplied for foreach() in /in/7PPJI on line 45 <!-- POST : --> Notice: Unable to unserialize: [O:4:"Post":3:{s:8:"*title";s:3:"hue";s:7:"*text";s:2:"br";s:10:"*filters";a:2:{i:0;O:6:"Filter":2:{s:10:"*pattern";s:6:"/gibe/";s:7:"*repl";s:9:"gibe moni";}i:1;O:6:"Filter":2:{s:10:"*pattern";s:6:"/moni/";s:7:"*repl";s:9:"i repor u";}}}]. Expected '"' but got 's'. in /in/7PPJI on line 58 BYE BITCH BYE BITCH BYE BITCH BYE BITCH
Output for 5.6.26 - 5.6.28
Notice: Array to string conversion in /in/7PPJI on line 43 WOAH ITS A FILTER "Array"<!-- POST hue: br -->BYE BITCH BYE BITCH O:4:"Post":3:{s:8:"*title";s:3:"hue";s:7:"*text";s:2:"br";s:10:"*filters";a:2:{i:0;O:6:"Filter":2:{s:10:"*pattern";s:6:"/gibe/";s:7:"*repl";s:9:"gibe moni";}i:1;O:6:"Filter":2:{s:10:"*pattern";s:6:"/moni/";s:7:"*repl";s:9:"i repor u";}}} Notice: unserialize(): Error at offset 27 of 237 bytes in /in/7PPJI on line 58 BYE BITCH BYE BITCH BYE BITCH BYE BITCH
Output for 5.6.25
Notice: Array to string conversion in /in/7PPJI on line 43 WOAH ITS A FILTER "Array"<!-- POST hue: br -->BYE BITCH BYE BITCH O:4:"Post":3:{s:8:"*title";s:3:"hue";s:7:"*text";s:2:"br";s:10:"*filters";a:2:{i:0;O:6:"Filter":2:{s:10:"*pattern";s:6:"/gibe/";s:7:"*repl";s:9:"gibe moni";}i:1;O:6:"Filter":2:{s:10:"*pattern";s:6:"/moni/";s:7:"*repl";s:9:"i repor u";}}} Notice: unserialize(): Error at offset 27 of 237 bytes in /in/7PPJI on line 58 BYE BITCH BYE BITCH BYE BITCH BYE BITCH WOAH ITS A FILTER "" Warning: Invalid argument supplied for foreach() in /in/7PPJI on line 44 <!-- POST : -->
Output for 5.2.14 - 5.2.17, 5.3.3 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/7PPJI on line 52
Process exited with code 255.
Output for 5.1.0 - 5.2.13, 5.3.0 - 5.3.2
Strict Standards: Redefining already defined constructor for class Filter in /in/7PPJI on line 10 Parse error: syntax error, unexpected '[' in /in/7PPJI on line 52
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Strict Standards: Redefining already defined constructor for class Filter in /in/7PPJI on line 10 Parse error: parse error, unexpected '[' in /in/7PPJI on line 52
Process exited with code 255.
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/7PPJI on line 4
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/7PPJI 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/7PPJI on line 4
Process exited with code 255.