3v4l.org

run code in 300+ PHP versions simultaneously
<?php if (!function_exists('str_contains')) { function str_contains(string $haystack, string $needle): bool { return '' === $needle || false !== strpos($haystack, $needle); } } if (!function_exists('str_ends_with')) { function str_ends_with(string $haystack, string $needle): bool { return '' === $needle || ('' !== $haystack && 0 === \substr_compare($haystack, $needle, -\strlen($needle))); } } if (!function_exists('str_starts_with')) { function str_starts_with(string $haystack, string $needle): bool { return 0 === \strncmp($haystack, $needle, \strlen($needle)); } } $methods = [ 'str_contains', 'str_starts_with', 'str_ends_with', ]; $types = [ 'string' => 'test', 'int' => 1, 'float' => 1.23, 'null' => null, 'true' => true, 'false' => false, 'object' => new StdClass(), 'array' => [], ]; $result = []; foreach ($methods as $method) { foreach ($types as $type => $val) { foreach (['first' => [$val, 'test'], 'second' => ['test', $val]] as $firstSecond => $args) { try { $res = $method(...$args); } catch (Error $e) { $res = 'Fatal error triggered'; } $result[$method][$type][$firstSecond] = $res; } } } var_export($result);

preferences:
25.89 ms | 402 KiB | 5 Q