3v4l.org

run code in 300+ PHP versions simultaneously
<?php function parse_literal($str) { $str = (string)$str; if (((string)(int)$str) === $str) { return (int)$str; } else if (((string)(float)$str) === $str) { return (float)$str; } else if (0 === strcasecmp($str, 'true')) { return true; } else if (0 === strcasecmp($str, 'false')) { return false; } else if (0 === strcasecmp($str, 'null')) { return false; } else if (preg_match('<^"((?:[^"\\\\]|\\\\.)*)"|\'((?:[^\'\\\\]|\\\\.)*)\'$>', $str)) { return eval('return ' . $str); } } var_dump(parse_literal('12')); var_dump(parse_literal('12.34')); var_dump(parse_literal('true')); var_dump(parse_literal('false')); var_dump(parse_literal('null')); var_dump(parse_literal('"hello world"')); var_dump(parse_literal('"string with \" quote and escape sequences\r\n"'));
Output for git.master, git.master_jit, rfc.property-hooks
int(12) float(12.34) bool(true) bool(false) bool(false) Parse error: syntax error, unexpected end of file, expecting ";" in /in/TH2kU(16) : eval()'d code on line 1
Process exited with code 255.

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
31.99 ms | 401 KiB | 8 Q