Skip to content

Additional difference between heredocs and nowdocs #1385

@HenrySwanson

Description

@HenrySwanson

Please complete the information below:

Where is the problem?

On the Source Code Fundamentals: Literals page, in the section about nowdoc string literals.

What is the problem?

The page says:

The two forms of string literal (heredoc, nowdoc) have the same semantics and constraints except that nowdoc literals do not support variable substitution.

However, there is an additional distinction not mentioned on this page: nowdocs also do not support backslash escapes. For example, the following will be parsed as a backslash and an n, not as a newline character:

$x = <<<EOT
\n
EOT

It's close to, but not quite, the same distinction as double-quoted and single-quoted strings (in single-quoted strings, \' is a single quote, but in a nowdoc, it seems to be two characters).


Please don't change anything below this point.


  • Build ID: HHVM=HHVM-4.164.0:HSL=v4.108.1:2024-02-08T13:44:46+0000:1fa47f258c6b68f8ec01899aa82fd6ffa0957109
  • Page requested: /hack/source-code-fundamentals/literals
  • Page requested at: Thu, 22 May 2025 00:12:05 +0000
  • Controller: GuidePageController

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions