14

Possible Duplicates:
Reference - What does this symbol mean in PHP?
PHP <<<EOB

I am trying to grok the use of END in the following code:

$javascript_autocomplete_text = <<<END
<script type="text/javascript">
    function split(val) {
        return val.split('\\n');
    }
</script>
Community
  • 1
  • 1
Jacko
  • 12,665
  • 18
  • 75
  • 126
  • 1
    oops there are no heredoc. So, here goes a dozen of equal answers – Your Common Sense Apr 04 '11 at 14:10
  • thanks, but I found no mention of <<< or END in that link. – Jacko Apr 04 '11 at 14:12
  • I've added your question, the linked duplicate and three additional into the Reference now. – Gordon Apr 04 '11 at 14:22
  • What does mean by "Heredocs can not be used for initializing class properties. Since PHP 5.3, this limitation is valid only for heredocs containing variables."? Someone, please update the answer explaining meaning of these sentences. – PHPLover Nov 26 '17 at 03:47

4 Answers4

14

Heredoc syntax:

A third way to delimit strings is the heredoc syntax: <<<. After this operator, an identifier is provided, then a newline. The string itself follows, and then the same identifier again to close the quotation.

The closing identifier must begin in the first column of the line. Also, the identifier must follow the same naming rules as any other label in PHP: it must contain only alphanumeric characters and underscores, and must start with a non-digit character or underscore.

Warning It is very important to note that the line with the closing identifier must contain no other characters, except a semicolon (;). That means especially that the identifier may not be indented, and there may not be any spaces or tabs before or after the semicolon. It's also important to realize that the first character before the closing identifier must be a newline as defined by the local operating system. This is \n on UNIX systems, including Mac OS X. The closing delimiter must also be followed by a newline.

If this rule is broken and the closing identifier is not "clean", it will not be considered a closing identifier, and PHP will continue looking for one. If a proper closing identifier is not found before the end of the current file, a parse error will result at the last line.

Heredocs can not be used for initializing class properties. Since PHP 5.3, this limitation is valid only for heredocs containing variables...

gnat
  • 6,213
  • 108
  • 53
  • 73
Emmerman
  • 2,371
  • 15
  • 9
1

Read it here: http://php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc

KingCrunch
  • 128,817
  • 21
  • 151
  • 173
0

It's part of the new heredoc string format in PHP.

ashleedawg
  • 20,365
  • 9
  • 72
  • 105
DShook
  • 14,833
  • 9
  • 45
  • 55
0

This seems to be a Heredoc

wallenborn
  • 4,158
  • 23
  • 39