In my file read function, if($theData = @fread($fh, filesize($myFile)) was returning false if the target failed contained nothing but a zero, so I added a check for integer (is_numeric). Is this safe?
function readfilecontents($myFile)
{
if($fh = @fopen($myFile, 'r'))
{
$theData = @fread($fh, filesize($myFile));
if($theData || is_numeric($theData))
{
if(@fclose($fh))
{
return $theData;
}
}
}
return false;
}
No, this is not safe – e.g. if you’re reading an empty file, your function will return false instead of an empty string. But there is no need for a function like this as file_get_contents() does the exact same thing (just faster).