2010-05-06 217 views
6

在以下代碼中,http://us2.php.net/manual/en/language.oop5.properties.php符號是什麼意思?Php <<<是什麼意思?

<?php 
class SimpleClass 
{ 
    // invalid property declarations: 
    public $var1 = 'hello ' . 'world'; 
    public $var2 = <<<EOD 
hello world 
EOD; 
    public $var3 = 1+2; 
    public $var4 = self::myStaticMethod(); 
    public $var5 = $myVar; 

    // valid property declarations: 
    public $var6 = myConstant; 
    public $var7 = array(true, false); 

    // This is allowed only in PHP 5.3.0 and later. 
    public $var8 = <<<'EOD' 
hello world 
EOD; 
} 
?> 
+0

張貼,代碼是不正確的 - 'EOD;'行不允許縮進。請注意,您鏈接到的頁面沒有縮進該部分。 – Amber 2010-05-06 10:03:31

回答

5

它被稱爲Heredoc syntax,可用於分配字符串值。

+0

以這種方式分配字符串有什麼好處? – Prospero 2010-05-06 10:51:30

+0

對於1而言,您不必擔心新線路運營商。 – 2010-05-06 11:44:05

+0

你也不必逃避引號。 – 2012-06-29 13:11:28