3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php class Renderer { function render(array $_data) { // normally you'd have some file you'd render from... $_data = $this->escapeData($_data); extract($_data, EXTR_SKIP); return <<<LIST {$foo}\n {$bar}\n {$baz}\n LIST; } private function escapeData(array $data) { $safe = []; foreach ($data as $var => $value) { if (is_array($value)) { $safe[$key] = $this->escapeData($value); } else { $safe[$key] = htmlspecialchars($value); } } return $safe; } } $renderer = new Renderer(); $unsafe = ['foo' => '<script>alert("xss");</script>', 'bar' => '<b>something</b>', 'baz' => '<i>foo</i>']; echo $renderer->render($unsafe);
based on dZPiQ
Output for 5.4.0 - 5.6.28, 7.0.0 - 7.1.0
Notice: Undefined variable: key in /in/rRFMo on line 23 Notice: Undefined variable: key in /in/rRFMo on line 23 Notice: Undefined variable: key in /in/rRFMo on line 23 Notice: Undefined variable: foo in /in/rRFMo on line 10 Notice: Undefined variable: bar in /in/rRFMo on line 11 Notice: Undefined variable: baz in /in/rRFMo on line 12
Output for hhvm-3.12.0
Notice: Undefined variable: foo in /in/rRFMo on line -1 Notice: Undefined variable: bar in /in/rRFMo on line -1 Notice: Undefined variable: baz in /in/rRFMo on line -1
Output for hhvm-3.10.0
Notice: Undefined variable: foo in /in/rRFMo on line 13 Notice: Undefined variable: bar in /in/rRFMo on line 13 Notice: Undefined variable: baz in /in/rRFMo on line 13
Output for 5.1.0 - 5.1.1, 5.1.3 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/rRFMo on line 18
Process exited with code 255.
Output for 5.1.2
Parse error: syntax error, unexpected '[' in /in/rRFMo on line 19
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_ARRAY, expecting '&' or T_VARIABLE in /in/rRFMo on line 5
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_ARRAY, expecting ')' in /in/rRFMo on line 5
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_ARRAY, expecting ')' in /in/rRFMo on line 5
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `')'' in /in/rRFMo on line 5
Process exited with code 255.