3v4l.org

run code in 300+ PHP versions simultaneously
<?php function stringCheck_TypeSafe(string $string) { $pos = strpos($string, 'cat'); if ($pos === 0) { return true; } return false; } function stringCheck_NotTypeSafe($string) { $pos = strpos($string, 'cat'); if ($pos != 'true') { return true; } return false; } echo "type safe string check, return should be true:\n"; var_dump(stringCheck_TypeSafe('cat')); echo "not type safe string check, return should be true:\n"; var_dump(stringCheck_NotTypeSafe('cat')); echo "not type safe string check, return should be false:\n"; var_dump(stringCheck_NotTypeSafe('a'));

preferences:
29.59 ms | 402 KiB | 5 Q