PHP syntax heredoc

It was interesting to me:

$foo = <<< EOT Hello, World! EOT; 

fair as

 $foo = <<<EOT Hello, World! EOT; 

and, in particular, is this true in all versions of PHP (or only in recent versions).

Interesting because I want to know if there is a syntactic space between the identifier <<< and first EOT . For example, my PHP interpreter 5.3.10 works correctly, but my vim text editor is not syntax - highlight heredoc in the same way if there is a space between <<< and EOT (the EOT identifier is painted white instead of purple).

So what is the deal? Are they legal in all versions of PHP or not?

+4
source share
3 answers

No, you should not provide space between <<and identifier. As stated in the PHP documentation:

(...) the identifier must follow the same naming conventions as any other label in PHP: it must contain only alphanumeric and underscore characters and must begin with a non-digital character or underscore .

Source: http://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc

-1
source

Tabs and spaces are allowed, and apparently these are quotation marks:

 <ST_IN_SCRIPTING>b?"<<<"{TABS_AND_SPACES}({LABEL}|([']{LABEL}['])|(["]{LABEL}["])){NEWLINE} { 

A source

Edit:

  • tabs and spaces allowed at least 2001
  • quotes were added in 2008
+4
source

The manual says (my attention) that

The third way to distinguish between strings is the heredoc syntax: << After this, the operator, the identifier is provided , then a newline.

For me, this means that space is optional (and will always be optional), since in the language as a whole, identifiers can be separated from neighboring tokens by any number of spaces - including without them.

+3
source

All Articles