Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does <<<END mean in PHP? [duplicate]

Tags:

php

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>
like image 513
Jacko Avatar asked Apr 04 '11 14:04

Jacko


People also ask

What is <<< EOD in PHP?

EOD = End Of Data, EOT = End of Text.

What does this -> mean in PHP?

The object operator, -> , is used in object scope to access methods and properties of an object. It's meaning is to say that what is on the right of the operator is a member of the object instantiated into the variable on the left side of the operator. Instantiated is the key term here.

What does &$ mean in PHP?

It means you pass a reference to the string into the method. All changes done to the string within the method will be reflected also outside that method in your code. See also: PHP's =& operator.

What does => mean in PHP array?

=> is the separator for associative arrays. In the context of that foreach loop, it assigns the key of the array to $user and the value to $pass .


1 Answers

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...

like image 60
Emmerman Avatar answered Sep 22 '22 20:09

Emmerman