matomo-org / component-ini

Read and write INI configurations.
GNU Lesser General Public License v3.0
50 stars 25 forks source link

Problem about IniReader::getFileContent method implementation #12

Closed peter279k closed 4 years ago

peter279k commented 4 years ago

As title, please look at following code about getFileContent method implementation approach:

.......
        if (function_exists('file_get_contents')) {
            return file_get_contents($filename);
        } elseif (function_exists('file')) {
            $ini = file($filename);
            if ($ini !== false) {
                return implode("\n", $ini);
            }
        } elseif (function_exists('fopen') && function_exists('fread')) {
            $handle = fopen($filename, 'r');
            if (!$handle) {
                return false;
            }
            $ini = fread($handle, filesize($filename));
            fclose($handle);
            return $ini;
        }

        return false;
......

It looks like the file_get_contents will be included on PHP version and it seems that using the function_exists is unnecessary.

To improve this approach, please consider following code:

......
    return file_get_contents($filename);
.......
tsteur commented 4 years ago

I'm not sure but maybe sometimes file_get_contents might not be available eg on certain hosters etc?

peter279k commented 4 years ago

Hi @tsteur, thanks for your reply. I agree with your point. And it can stay these codes.

Closed.