Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Heredoc: what does the commonly used 'EOT' actually mean?

Tags:

php

heredoc

PHP's Heredoc examples always seem to use EOT (and sometimes EOD) as the seperating string, while it is actually possible to use any string here. This works:

$mystring = <<<EOT
     Foo
     Bar
     Baz
EOT;

While this works as well:

$mystring = <<<MONKIES
     Foo
     Bar
     Baz
MONKIES;

Does EOT actually stand for something and if so, what?

like image 423
Aron Rotteveel Avatar asked Mar 10 '11 10:03

Aron Rotteveel


People also ask

What does EOT stand for PHP?

So, for example, we could use the string EOT (end of text) for our delimiter, meaning that we can use double quotes and single quotes freely within the body of the text—the string only ends when we type EOT .

What is the use of heredoc?

Here document (Heredoc) is an input or file stream literal that is treated as a special block of code. This block of code will be passed to a command for processing. Heredoc originates in UNIX shells and can be found in popular Linux shells like sh, tcsh, ksh, bash, zsh, csh.

What is heredoc give example?

Heredoc's are equivalent to a double quoted string. That means any variables in the string will get substitued for their respective values. We could rewrite the double quoted string example above as a heredoc:- $foo = 'bar'; echo <<<EOT Hello $foo Goodbye! EOT; // Output:- // Hello bar // Goodbye!

What is a heredoc string?

In computing, a here document (here-document, here-text, heredoc, hereis, here-string or here-script) is a file literal or input stream literal: it is a section of a source code file that is treated as if it were a separate file.


4 Answers

​It stands for "End Of Text".​

like image 61
Ignacio Vazquez-Abrams Avatar answered Oct 14 '22 16:10

Ignacio Vazquez-Abrams


Actually end of text would be ETXEOT is end of transmission.

Reference: ASCII - Wikipedia

like image 24
Fleshgrinder Avatar answered Oct 14 '22 14:10

Fleshgrinder


Short answer

Probably End Of Text and End Of Data.

Long answer

The only ones who can tell you definitively what the acronyms mean are the authors of the original (and current) documentation. But based on an early version of the documentation which mentions "here doc text", I think one could plausibly assume that EOT is intended to mean End of Text.

Similarly, the current documentation makes a comparison between Nowdocs and SGML <![CDATA[ ]]> sections, so a reasonable assumption would be that EOD stands for End Of Data.

Sure, there's a definition of EOT in the ASCII standard, but that refers to a single character 0416 and this definition doesn't transfer to anything else unless explicitly stated. About the only thing we can learn from the ASCII standard in this regard is the encoding of the three letters E, O and T.

This is all guesswork of course, but these are the only sensible explanations I can think of. Personally, I prefer to avoid the whole issue by using a single underscore (<<<_).

like image 28
Nisse Engström Avatar answered Oct 14 '22 16:10

Nisse Engström


I prefer to go for the TRON reference and use 'EOL' (End of Line).

like image 33
siliconrockstar Avatar answered Oct 14 '22 15:10

siliconrockstar