- var_dump: documentation ( source)
- strpos: documentation ( source)
<?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'));