3v4l.org

run code in 300+ PHP versions simultaneously
<?php if (defined('HHVM_VERSION')) { exit; } // https://www.mail-archive.com/internals@lists.php.net/msg87079.html function str_begins($a, $b) { return substr_compare($a, $b, 0, strlen($b)) === 0; } function str_ends($a, $b) { return substr_compare($a, $b, -strlen($b)) === 0; } // Let's test edge cases $funcs = [ 'str_begins', 'str_ends', ]; $tests = [ // array(array($main, $part), $expected) array(array("foo", "foo"), true), array(array("foo", ""), true), array(array("", "foo"), false), array(array("", ""), true), ]; foreach ($funcs as $func) { foreach ($tests as list(list($main, $part), $expected)) { echo $func . '(' . var_export($main, true) . ', ' . var_export($part, true) . '):' . PHP_EOL; echo " - Expected: "; var_dump($expected); echo " - Actual: "; var_dump($actual = $func($main, $part)); if ($actual !== $expected) { echo " => DIFF!" . PHP_EOL; } echo PHP_EOL; } echo PHP_EOL; }
Output for git.master, git.master_jit, rfc.property-hooks
str_begins('foo', 'foo'): - Expected: bool(true) - Actual: bool(true) str_begins('foo', ''): - Expected: bool(true) - Actual: bool(true) str_begins('', 'foo'): - Expected: bool(false) - Actual: bool(false) str_begins('', ''): - Expected: bool(true) - Actual: bool(true) str_ends('foo', 'foo'): - Expected: bool(true) - Actual: bool(true) str_ends('foo', ''): - Expected: bool(true) - Actual: bool(false) => DIFF! str_ends('', 'foo'): - Expected: bool(false) - Actual: bool(false) str_ends('', ''): - Expected: bool(true) - Actual: bool(true)

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:
45.45 ms | 402 KiB | 8 Q