If I have a short function that opens a file and reads a line, do I need to close the file? Or will PHP do this automatically when execution exits the function and $fh is garbage collected?

function first_line($file) {
    $fh = fopen($file);
    $first_line = fgets($fh);
    fclose($fh);
    return $first_line;
}

could then be simplified to

function first_line($file) {
    return fgets(fopen($file));
}

This is of course theoretical right now, as this code doesn't have any error handling.

Edit
Report