Coding standards for long strings? I've been looking for some official guidelines on how to format long strings in module code, but the closest thing I've found is an ambiguous section on indenting long SQL queries which suggests any of the following styles:

$text = '
  Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean ligula odio,
  hendrerit consectetur porta vitae, sollicitudin sit amet eros. Integer
  hendrerit varius felis id dignissim.
';

$text = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean ligula'
. 'odio, hendrerit consectetur porta vitae, sollicitudin sit amet eros. Integer'
. 'hendrerit varius felis id dignissim.'
;

$text = &lt;&lt;&lt;TEXT
  Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean ligula odio,
  hendrerit consectetur porta vitae, sollicitudin sit amet eros. Integer
  hendrerit varius felis id dignissim.
TEXT;


The Drupal Coding Standards talk about how to use the concatenation assignment operator:

$string .= 'Foo';
$string .= $bar;
$string .= baz();


but they don't actually state whether single long strings should be broken up that way.

To add further confusion, the Coder module handles long strings differently again in its "good.php" test file:

$text = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean ' .
        'ligula odio, hendrerit consectetur porta vitae, sollicitudin sit ' .
        'amet eros. Integer hendrerit varius felis id dignissim.';


Personally, I've just been doing it like this until now:

$text = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean ligula
        odio, hendrerit consectetur porta vitae, sollicitudin sit amet eros.
        Integer hendrerit varius felis id dignissim.';


However, I'd like to start doing it the "right" way (if there is one). Does anyone have a definitive answer?
Drupal does not restrict the usage of long strings in code. It is advisable to concatenate each line ($output .= '...';) for a readable code, but as you can see in Drupal code, long strings are not broken up, especially when used with t():

function field_help($route_name, RouteMatchInterface $route_match) {
  switch ($route_name) {
    case 'help.page.field':
      $field_ui_url = \Drupal::moduleHandler()-&gt;moduleExists('field_ui') ? \Drupal::url('help.page', array('name' =&gt; 'field_ui')) : '#';
      $output = '';
      $output .= '&lt;h3&gt;' . t('About') . '&lt;/h3&gt;';
      $output .= '&lt;p&gt;' . t('The Field module allows custom data fields to be defined for &lt;em&gt;entity&lt;/em&gt; types (see below). The Field module takes care of storing, loading, editing, and rendering field data. Most users will not interact with the Field module directly, but will instead use the &lt;a href=":field-ui-help"&gt;Field UI module&lt;/a&gt; user interface. Module developers can use the Field API to make new entity types "fieldable" and thus allow fields to be attached to them. For more information, see the &lt;a href=":field"&gt;online documentation for the Field module&lt;/a&gt;.', array(':field-ui-help' =&gt; (\Drupal::moduleHandler()-&gt;moduleExists('field_ui')) ? \Drupal::url('help.page', array('name' =&gt; 'field_ui')) :'#', ':field' =&gt; 'https://www.drupal.org/documentation/modules/field')). '&lt;/p&gt;';
      $output .= '&lt;h3&gt;' . t('Terminology') . '&lt;/h3&gt;';
      $output .= '&lt;dl&gt;';
      $output .= '&lt;dt&gt;' . t('Entities and entity types') . '&lt;/dt&gt;';
      $output .= '&lt;dd&gt;' . t('The website\'s content and configuration is managed using &lt;em&gt;entities&lt;/em&gt;, which are grouped into &lt;em&gt;entity types&lt;/em&gt;. &lt;em&gt;Content entity types&lt;/em&gt; are the entity types for site content (such as the main site content, comments, custom blocks, taxonomy terms, and user accounts). &lt;em&gt;Configuration entity types&lt;/em&gt; are used to store configuration information for your site, such as individual views in the Views module, and settings for your main site content types.') . '&lt;/dd&gt;';
      $output .= '&lt;dt&gt;' . t('Entity sub-types') . '&lt;/dt&gt;';
      $output .= '&lt;dd&gt;' . t('Some content entity types are further grouped into sub-types (for example, you could have article and page content types within the main site content entity type, and tag and category vocabularies within the taxonomy term entity type); other entity types, such as user accounts, do not have sub-types. Programmers use the term &lt;em&gt;bundle&lt;/em&gt; for entity sub-types.') . '&lt;/dd&gt;';
      $output .= '&lt;dt&gt;' . t('Fields and field types') . '&lt;/dt&gt;';
      $output .= '&lt;dd&gt;' . t('Content entity types and sub-types store most of their text, file, and other information in &lt;em&gt;fields&lt;/em&gt;. Fields are grouped by &lt;em&gt;field type&lt;/em&gt;; field types define what type of data can be stored in that field, such as text, images, or taxonomy term references.') . '&lt;/dd&gt;';


I would stick with this drupal usage, this is the best compromise for usage and good readability. Your first examples looks good, but adds extra line feeds. The second example is not good to read and the third is often used in scripts, but not very common in php code.