public static function writeStringToFile($string, $filename, $append = false)
    {
        $errorHandler = static::getErrorHandler();
        
        $result = false;
        if ($append === true) {
            $result = file_put_contents($filename, $string, FILE_APPEND);
        } else {
            $result = file_put_contents($filename, $string);
        }
        
        if ($result === false) {
            $error = error_get_last();
            $errorMessage = null;
            if ($error != null && array_key_exists('message', $error)) {
                $errorMessage = $error['message'];
            }
            
            if (isset($errorMessage)) {
                $errorHandler->throwException(
                    'An error occurred in output file "'.$filename.'": '.$errorMessage,
                    ErrorHandlerInterface::OUTPUT_FILE_ERROR
                );
            } else { // @codeCoverageIgnore
                $errorHandler->throwException(
                    'An error occurred in output file "'.$filename.'"',
                    ErrorHandlerInterface::OUTPUT_FILE_ERROR
                );
            } // @codeCoverageIgnore
        } // @codeCoverageIgnore
            
        return $result;
    }