3v4l.org

run code in 300+ PHP versions simultaneously
<?php $fs = array(); $fs[] = function ($string, $end) { $len = strlen($end); if ($len == 0) { return true; } if (strlen($string) < $len) { return false; } return (substr_compare($string, $end, -$len, $len)); }; $fs[] = function ($string, $end) { $len = strlen($end); if ($len == 0) { return true; } if (strlen($string) < $len) { return false; } return (substr_compare($string, $end, -$len)); }; $fs[] = function ($string, $end) { $len = strlen($end); if ($len == 0) { return true; } return (substr_compare($string, $end, -$len, $len)); }; $fs[] = function ($string, $end) { $len = strlen($end); if ($len == 0) { return true; } return (substr_compare($string, $end, -$len)); }; $fs[] = function ($string, $end) { $len = strlen($end); return (substr_compare($string, $end, -$len, $len)); }; $fs[] = function ($string, $end) { $len = strlen($end); return (substr_compare($string, $end, -$len)); }; foreach ($fs as $f) { var_dump('---------------------------------'); var_dump($f('foobar', 'foobar')); var_dump($f('foobar', 'foo')); var_dump($f('foobar', 'bar')); var_dump($f('foobar', 'foobarbaz')); var_dump($f('foobar', '')); var_dump($f('', '')); var_dump($f('', 'foobar')); }
Output for 8.2.0 - 8.2.18, 8.3.0 - 8.3.7
string(33) "---------------------------------" int(0) int(-265725) int(0) bool(false) bool(true) bool(true) bool(false) string(33) "---------------------------------" int(0) int(-265725) int(0) bool(false) bool(true) bool(true) bool(false) string(33) "---------------------------------" int(0) int(-265725) int(0) int(-1) bool(true) bool(true) int(-1) string(33) "---------------------------------" int(0) int(-265725) int(0) int(-1) bool(true) bool(true) int(-1) string(33) "---------------------------------" int(0) int(-265725) int(0) int(-1) int(0) int(0) int(-1) string(33) "---------------------------------" int(0) int(-265725) int(0) int(-1) int(1) int(0) int(-1)
Output for 7.3.30 - 7.3.33, 7.4.5, 7.4.20, 7.4.23 - 7.4.33, 8.0.1, 8.0.5 - 8.0.7, 8.0.9 - 8.0.30, 8.1.0 - 8.1.28
string(33) "---------------------------------" int(0) int(-265725) int(0) bool(false) bool(true) bool(true) bool(false) string(33) "---------------------------------" int(0) int(-265725) int(0) bool(false) bool(true) bool(true) bool(false) string(33) "---------------------------------" int(0) int(-265725) int(0) int(-3) bool(true) bool(true) int(-6) string(33) "---------------------------------" int(0) int(-265725) int(0) int(-3) bool(true) bool(true) int(-6) string(33) "---------------------------------" int(0) int(-265725) int(0) int(-3) int(0) int(0) int(-6) string(33) "---------------------------------" int(0) int(-265725) int(0) int(-3) int(6) int(0) int(-6)
Output for 7.2.29 - 7.2.33, 7.3.16 - 7.3.29, 7.4.0 - 7.4.4, 7.4.6 - 7.4.16, 7.4.21 - 7.4.22, 8.0.0, 8.0.2 - 8.0.3, 8.0.8
string(33) "---------------------------------" int(0) int(-4) int(0) bool(false) bool(true) bool(true) bool(false) string(33) "---------------------------------" int(0) int(-4) int(0) bool(false) bool(true) bool(true) bool(false) string(33) "---------------------------------" int(0) int(-4) int(0) int(-3) bool(true) bool(true) int(-6) string(33) "---------------------------------" int(0) int(-4) int(0) int(-3) bool(true) bool(true) int(-6) string(33) "---------------------------------" int(0) int(-4) int(0) int(-3) int(0) int(0) int(-6) string(33) "---------------------------------" int(0) int(-4) int(0) int(-3) int(6) int(0) int(-6)
Output for 5.5.24 - 5.5.35, 5.6.8 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.20, 7.2.0
string(33) "---------------------------------" int(0) int(-4) int(0) bool(false) bool(true) bool(true) bool(false) string(33) "---------------------------------" int(0) int(-4) int(0) bool(false) bool(true) bool(true) bool(false) string(33) "---------------------------------" int(0) int(-4) int(0) int(-3) bool(true) bool(true) Warning: substr_compare(): The start position cannot exceed initial string length in /in/cMDtA on line 31 bool(false) string(33) "---------------------------------" int(0) int(-4) int(0) int(-3) bool(true) bool(true) Warning: substr_compare(): The start position cannot exceed initial string length in /in/cMDtA on line 39 bool(false) string(33) "---------------------------------" int(0) int(-4) int(0) int(-3) int(0) int(0) Warning: substr_compare(): The start position cannot exceed initial string length in /in/cMDtA on line 44 bool(false) string(33) "---------------------------------" int(0) int(-4) int(0) int(-3) int(6) Warning: substr_compare(): The start position cannot exceed initial string length in /in/cMDtA on line 49 bool(false) Warning: substr_compare(): The start position cannot exceed initial string length in /in/cMDtA on line 49 bool(false)
Output for 5.4.0 - 5.4.45
string(33) "---------------------------------" int(0) int(-4) int(0) bool(false) bool(true) bool(true) bool(false) string(33) "---------------------------------" int(0) int(-4) int(0) bool(false) bool(true) bool(true) bool(false) string(33) "---------------------------------" int(0) int(-4) int(0) int(-3) bool(true) bool(true) Warning: substr_compare(): The start position cannot exceed initial string length in /in/cMDtA on line 31 bool(false) string(33) "---------------------------------" int(0) int(-4) int(0) int(-3) bool(true) bool(true) Warning: substr_compare(): The start position cannot exceed initial string length in /in/cMDtA on line 39 bool(false) string(33) "---------------------------------" int(0) int(-4) int(0) int(-3) Warning: substr_compare(): The length must be greater than zero in /in/cMDtA on line 44 bool(false) Warning: substr_compare(): The length must be greater than zero in /in/cMDtA on line 44 bool(false) Warning: substr_compare(): The start position cannot exceed initial string length in /in/cMDtA on line 44 bool(false) string(33) "---------------------------------" int(0) int(-4) int(0) int(-3) int(6) Warning: substr_compare(): The start position cannot exceed initial string length in /in/cMDtA on line 49 bool(false) Warning: substr_compare(): The start position cannot exceed initial string length in /in/cMDtA on line 49 bool(false)
Output for 5.3.0 - 5.3.29
string(33) "---------------------------------" int(0) int(-4) int(0) bool(false) bool(true) bool(true) bool(false) string(33) "---------------------------------" int(0) int(-4) int(0) bool(false) bool(true) bool(true) bool(false) string(33) "---------------------------------" int(0) int(-4) int(0) int(0) bool(true) bool(true) Warning: substr_compare(): The start position cannot exceed initial string length in /in/cMDtA on line 31 bool(false) string(33) "---------------------------------" int(0) int(-4) int(0) int(-3) bool(true) bool(true) Warning: substr_compare(): The start position cannot exceed initial string length in /in/cMDtA on line 39 bool(false) string(33) "---------------------------------" int(0) int(-4) int(0) int(0) Warning: substr_compare(): The length must be greater than zero in /in/cMDtA on line 44 bool(false) Warning: substr_compare(): The length must be greater than zero in /in/cMDtA on line 44 bool(false) Warning: substr_compare(): The start position cannot exceed initial string length in /in/cMDtA on line 44 bool(false) string(33) "---------------------------------" int(0) int(-4) int(0) int(-3) int(6) Warning: substr_compare(): The start position cannot exceed initial string length in /in/cMDtA on line 49 bool(false) Warning: substr_compare(): The start position cannot exceed initial string length in /in/cMDtA on line 49 bool(false)
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17
Parse error: syntax error, unexpected T_FUNCTION in /in/cMDtA on line 3
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_FUNCTION in /in/cMDtA on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/cMDtA on line 3
Process exited with code 255.

preferences:
215.29 ms | 401 KiB | 312 Q