3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?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 5.5.24 - 5.6.28, 7.0.0 - 7.1.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 hhvm-3.12.0
string(33) "---------------------------------" int(0) int(-1) int(0) bool(false) bool(true) bool(true) bool(false) string(33) "---------------------------------" int(0) int(-1) int(0) bool(false) bool(true) bool(true) bool(false) string(33) "---------------------------------" int(0) int(-1) int(0) int(-1) bool(true) bool(true) Warning: The start position cannot exceed initial string length in /in/cMDtA on line 31 bool(false) string(33) "---------------------------------" int(0) int(-1) int(0) int(-1) bool(true) bool(true) Warning: The start position cannot exceed initial string length in /in/cMDtA on line 39 bool(false) string(33) "---------------------------------" int(0) int(-1) int(0) int(-1) Warning: The length must be greater than zero in /in/cMDtA on line 44 bool(false) Warning: The length must be greater than zero in /in/cMDtA on line 44 bool(false) Warning: The start position cannot exceed initial string length in /in/cMDtA on line 44 bool(false) string(33) "---------------------------------" int(0) int(-1) int(0) int(-1) int(1) Warning: The start position cannot exceed initial string length in /in/cMDtA on line 49 bool(false) Warning: The start position cannot exceed initial string length in /in/cMDtA on line 49 bool(false)
Output for hhvm-3.10.0

Process exited with code 153.
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.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.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.