Victor Roman wrote :1780
That function will be written in a more readable and easy way. I assume you're writing a wrapper over realpath and appending the trailing directory separator character (because this function, otherwise, is non-sense).
<?
function Path($path)
{
/* Checks if the file exists */
if (false == file_exists($path))
return false;
/* Now takes the real system file path */
$path = realpath($path);
/*
* If the given path is a directory we take care of this and
* appends the trailing directory separator character
*/
if (is_dir($path) && $path[strlen($path)] != DIRECTORY_SEPARATOR)
$path .= DIRECTORY_SEPARATOR;
/* Returns the translated path */
return $path;
}
?>
Alix Axel wrote :1786
The function you have rewritten doesn't seem more readable to me (maybe it's just a matter of taste since you are returning false on the beginning and not at the end, one could argue that testing for more probable conditions at the start is wiser in terms of performance than the inverse).
Anyway your function is in fact useless since you forgot to put (or didn't understand why) str_replace is there - the forwarding slash (/) works on both Windows and *nix environments.