3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $fmt = "%-12s %-20s %-20s %-10s %-5s\n"; function json_cmp($x, $y) { global $fmt; $error = array("-", "FAIL"); printf($fmt, var_export($x, true), str_replace("\n", "", var_export($y, true)), str_replace("\n", "", var_export(json_decode($x), true)), $error[json_last_error() > 0], $error[json_decode($x) !== $y] ); } printf($fmt, "JSON", "Expected", "Actual", "JSON_ERROR", "PASS"); printf("---------------------------------------------------------------------- \n"); // works json_cmp("true", true); // fails - is actually true json_cmp("tRue", NULL); // fails - is actually NULL json_cmp("true ", true); // works json_cmp("[true ] ", array(true)); json_cmp("[ true ] ", array(true)); json_cmp("[true] ", array(true)); // works, even though the non-array version fails json_cmp("[tRue]", NULL); json_cmp("0", 0); json_cmp("1", 1); json_cmp("false", false); json_cmp("'foo'", NULL); json_cmp('"foo"', "foo"); json_cmp('1.123', 1.123); json_cmp('1.123 ', 1.123); json_cmp(' 1.123', 1.123); json_cmp('42', 42); json_cmp('42 ', 42); json_cmp(' 42', 42); json_cmp(".123", 0.123);
Output for 7.0.12 - 7.1.0
JSON Expected Actual JSON_ERROR PASS ---------------------------------------------------------------------- 'true' true true - - 'tRue' NULL NULL FAIL - 'true ' true true - - '[true ] ' array ( 0 => true,) array ( 0 => true,) - - '[ true ] ' array ( 0 => true,) array ( 0 => true,) - - '[true] ' array ( 0 => true,) array ( 0 => true,) - - '[tRue]' NULL NULL FAIL - '0' 0 0 - - '1' 1 1 - - 'false' false false - - '\'foo\'' NULL NULL FAIL - '"foo"' 'foo' 'foo' - - '1.123' 1.123 1.123 - - '1.123 ' 1.123 1.123 - - ' 1.123' 1.123 1.123 - - '42' 42 42 - - '42 ' 42 42 - - ' 42' 42 42 - - '.123' 0.123 NULL FAIL FAIL
Output for 7.0.0 - 7.0.6
JSON Expected Actual JSON_ERROR PASS ---------------------------------------------------------------------- 'true' true true - - 'tRue' NULL NULL FAIL - 'true ' true true - - '[true ] ' array ( 0 => true,) array ( 0 => true,) - - '[ true ] ' array ( 0 => true,) array ( 0 => true,) - - '[true] ' array ( 0 => true,) array ( 0 => true,) - - '[tRue]' NULL NULL FAIL - '0' 0 0 - - '1' 1 1 - - 'false' false false - - '\'foo\'' NULL NULL FAIL - '"foo"' 'foo' 'foo' - - '1.123' 1.12299999999999999822364 1.12299999999999999822364 - - '1.123 ' 1.12299999999999999822364 1.12299999999999999822364 - - ' 1.123' 1.12299999999999999822364 1.12299999999999999822364 - - '42' 42 42 - - '42 ' 42 42 - - ' 42' 42 42 - - '.123' 0.122999999999999998223643 NULL FAIL FAIL
Output for hhvm-3.10.0 - 3.12.0
JSON Expected Actual JSON_ERROR PASS ---------------------------------------------------------------------- 'true' true true - - 'tRue' NULL true - FAIL 'true ' true true - - '[true ] ' array ( 0 => true,) array ( 0 => true,) - - '[ true ] ' array ( 0 => true,) array ( 0 => true,) - - '[true] ' array ( 0 => true,) array ( 0 => true,) - - '[tRue]' NULL NULL FAIL - '0' 0 0 - - '1' 1 1 - - 'false' false false - - '\'foo\'' NULL NULL FAIL - '"foo"' 'foo' 'foo' - - '1.123' 1.123 1.123 - - '1.123 ' 1.123 NULL FAIL FAIL ' 1.123' 1.123 1.123 - - '42' 42 42 - - '42 ' 42 NULL FAIL FAIL ' 42' 42 42 - - '.123' 0.123 0.123 - -
Output for 5.6.28
JSON Expected Actual JSON_ERROR PASS ---------------------------------------------------------------------- 'true' true true - - 'tRue' NULL NULL FAIL - 'true ' true true - - '[true ] ' array ( 0 => true,) array ( 0 => true,) - - '[ true ] ' array ( 0 => true,) array ( 0 => true,) - - '[true] ' array ( 0 => true,) array ( 0 => true,) - - '[tRue]' NULL NULL FAIL - '0' 0 0 - - '1' 1 1 - - 'false' false false - - '\'foo\'' NULL NULL FAIL - '"foo"' 'foo' 'foo' - - '1.123' 1.123 1.123 - - '1.123 ' 1.123 1.123 - - ' 1.123' 1.123 1.123 - - '42' 42 42 - - '42 ' 42 42 - - ' 42' 42 42 - - '.123' 0.123 0.123 - -
Output for 5.6.8 - 5.6.21
JSON Expected Actual JSON_ERROR PASS ---------------------------------------------------------------------- 'true' true true - - 'tRue' NULL NULL FAIL - 'true ' true true - - '[true ] ' array ( 0 => true,) array ( 0 => true,) - - '[ true ] ' array ( 0 => true,) array ( 0 => true,) - - '[true] ' array ( 0 => true,) array ( 0 => true,) - - '[tRue]' NULL NULL FAIL - '0' 0 0 - - '1' 1 1 - - 'false' false false - - '\'foo\'' NULL NULL FAIL - '"foo"' 'foo' 'foo' - - '1.123' 1.12299999999999999822364 1.12299999999999999822364 - - '1.123 ' 1.12299999999999999822364 1.12299999999999999822364 - - ' 1.123' 1.12299999999999999822364 1.12299999999999999822364 - - '42' 42 42 - - '42 ' 42 42 - - ' 42' 42 42 - - '.123' 0.122999999999999998223643 0.122999999999999998223643 - -
Output for 5.4.23 - 5.5.35
JSON Expected Actual JSON_ERROR PASS ---------------------------------------------------------------------- 'true' true true - - 'tRue' NULL true - FAIL 'true ' true true - - '[true ] ' array ( 0 => true,) array ( 0 => true,) - - '[ true ] ' array ( 0 => true,) array ( 0 => true,) - - '[true] ' array ( 0 => true,) array ( 0 => true,) - - '[tRue]' NULL NULL FAIL - '0' 0 0 - - '1' 1 1 - - 'false' false false - - '\'foo\'' NULL NULL FAIL - '"foo"' 'foo' 'foo' - - '1.123' 1.12299999999999999822364 1.12299999999999999822364 - - '1.123 ' 1.12299999999999999822364 1.12299999999999999822364 - - ' 1.123' 1.12299999999999999822364 1.12299999999999999822364 - - '42' 42 42 - - '42 ' 42 42 - - ' 42' 42 42 - - '.123' 0.122999999999999998223643 0.122999999999999998223643 - -
Output for 5.4.22
JSON Expected Actual JSON_ERROR PASS ---------------------------------------------------------------------- 'true' true true - - 'tRue' NULL true - FAIL 'true ' true NULL FAIL FAIL '[true ] ' array ( 0 => true,) array ( 0 => true,) - - '[ true ] ' array ( 0 => true,) array ( 0 => true,) - - '[true] ' array ( 0 => true,) array ( 0 => true,) - - '[tRue]' NULL NULL FAIL - '0' 0 0 - - '1' 1 1 - - 'false' false false - - '\'foo\'' NULL NULL FAIL - '"foo"' 'foo' 'foo' - - '1.123' 1.12299999999999999822364 1.12299999999999999822364 - - '1.123 ' 1.12299999999999999822364 NULL FAIL FAIL ' 1.123' 1.12299999999999999822364 1.12299999999999999822364 - - '42' 42 42 - - '42 ' 42 NULL FAIL FAIL ' 42' 42 42 - - '.123' 0.122999999999999998223643 0.122999999999999998223643 - -
Output for 5.3.0 - 5.4.21
JSON Expected Actual JSON_ERROR PASS ---------------------------------------------------------------------- 'true' true true - - 'tRue' NULL true - FAIL 'true ' true NULL FAIL FAIL '[true ] ' array ( 0 => true,) array ( 0 => true,) - - '[ true ] ' array ( 0 => true,) array ( 0 => true,) - - '[true] ' array ( 0 => true,) array ( 0 => true,) - - '[tRue]' NULL NULL FAIL - '0' 0 0 - - '1' 1 1 - - 'false' false false - - '\'foo\'' NULL NULL FAIL - '"foo"' 'foo' 'foo' - - '1.123' 1.123 1.123 - - '1.123 ' 1.123 NULL FAIL FAIL ' 1.123' 1.123 1.123 - - '42' 42 42 - - '42 ' 42 NULL FAIL FAIL ' 42' 42 42 - - '.123' 0.123 0.123 - -
Output for 5.2.0 - 5.2.17
JSON Expected Actual JSON_ERROR PASS ---------------------------------------------------------------------- Fatal error: Call to undefined function json_last_error() in /in/nTHph on line 12
Process exited with code 255.
Output for 5.0.0 - 5.1.6
JSON Expected Actual JSON_ERROR PASS ---------------------------------------------------------------------- Fatal error: Call to undefined function json_decode() in /in/nTHph on line 11
Process exited with code 255.
Output for 4.4.5 - 4.4.9
JSON Expected Actual JSON_ERROR PASS ---------------------------------------------------------------------- Fatal error: Call to undefined function: json_decode() in /in/nTHph on line 11
Process exited with code 255.
Output for 4.3.2 - 4.4.4
JSON Expected Actual JSON_ERROR PASS ---------------------------------------------------------------------- Fatal error: Call to undefined function: json_decode() in /in/nTHph on line 11
Process exited with code 255.
Output for 4.3.0 - 4.3.1
JSON Expected Actual JSON_ERROR PASS ---------------------------------------------------------------------- Fatal error: Call to undefined function: json_decode() in /in/nTHph on line 11