public static function read(string $path, int $offset = 0, int $maxLength = null) : string
    {
        $exception = null;

        try {
            $result = ErrorCatcher::run(static function() use ($path, $offset, $maxLength) {
                if ($maxLength === null) {
                    return file_get_contents($path, false, null, $offset);
                }

                return file_get_contents($path, false, null, $offset, $maxLength);
            });

            if ($result !== false) {
                return $result;
            }
        } catch (\ErrorException $e) {
            $exception = $e;
        }

        throw new IoException('Error reading from ' . $path, 0, $exception);
    }
public static function read(string $path, int $offset = 0, int $maxLength = null) : string
    {
        $exception = null;

        try {
            $result = ErrorCatcher::run(static function() use ($path, $offset, $maxLength) {
                if ($maxLength === null) {
                    return file_get_contents($path, false, null, $offset);
                }

                return file_get_contents($path, false, null, $offset, $maxLength);
            });

            if ($result !== false) {
                return $result;
            }
        } catch (\ErrorException $e) {
            $exception = $e;
        }

        throw new IoException('Error reading from ' . $path, 0, $exception);
    }
public static function read ( string $ path , int $ offset = 0 , int $ maxLength = null ) : string { $ exception = null ; try { $ result = ErrorCatcher :: run ( static function ( ) use ( $ path , $ offset , $ maxLength ) { if ( $ maxLength === null ) { return file_get_contents ( $ path , false , null , $ offset ) ; } return file_get_contents ( $ path , false , null , $ offset , $ maxLength ) ; } ) ; if ( $ result !== false ) { return $ result ; } } catch ( \ ErrorException $ e ) { $ exception = $ e ; } throw new IoException ( 'Error reading from ' . $ path , 0 , $ exception ) ; }
Reads data from a file.

Always be careful when reading a file in memory, as it may exceed the memory limit.

@param string   $path      The path to the file.
@param int      $offset    The offset where the reading starts on the original stream.
Negative offsets count from the end of the stream.
@param int|null $maxLength Maximum length of data read. The default is to read until end of file is reached.

@return string The file contents.

@throws IoException If an error occurs.
Reads data from a file .