public static function write(string $path, $data, bool $append = false, bool $lock = false) : int
    {
        $flags = 0;

        if ($append) {
            $flags |= FILE_APPEND;
        }
        if ($lock) {
            $flags |= LOCK_EX;
        }

        $exception = null;

        try {
            $result = ErrorCatcher::run(static function() use ($path, $data, $flags) {
                return file_put_contents($path, $data, $flags);
            });

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

        throw new IoException('Error writing to ' . $path, 0, $exception);
    }
public static function write(string $path, $data, bool $append = false, bool $lock = false) : int
    {
        $flags = 0;

        if ($append) {
            $flags |= FILE_APPEND;
        }
        if ($lock) {
            $flags |= LOCK_EX;
        }

        $exception = null;

        try {
            $result = ErrorCatcher::run(static function() use ($path, $data, $flags) {
                return file_put_contents($path, $data, $flags);
            });

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

        throw new IoException('Error writing to ' . $path, 0, $exception);
    }
public static function write ( string $ path , $ data , bool $ append = false , bool $ lock = false ) : int { $ flags = 0 ; if ( $ append ) { $ flags |= FILE_APPEND ; } if ( $ lock ) { $ flags |= LOCK_EX ; } $ exception = null ; try { $ result = ErrorCatcher :: run ( static function ( ) use ( $ path , $ data , $ flags ) { return file_put_contents ( $ path , $ data , $ flags ) ; } ) ; if ( $ result !== false ) { return $ result ; } } catch ( \ ErrorException $ e ) { $ exception = $ e ; } throw new IoException ( 'Error writing to ' . $ path , 0 , $ exception ) ; }
Writes data to a file.

If the file already exists, it will be overwritten, unless `$append` is set to `true`.

@param string          $path  The path to the file.
@param string|resource $data  The data to write, as a string or a stream resource.
@param bool            $append Whether to append if the file already exists. Defaults to false (overwrite).
@param bool            $lock   Whether to acquire an exclusive lock on the file. Defaults to false.

@return int The number of bytes written.

@throws IoException If an error occurs.
Writes data to a file .