3v4l.org

run code in 300+ PHP versions simultaneously
<?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 git.master, git.master_jit, rfc.property-hooks
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

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:
37.65 ms | 404 KiB | 8 Q