2010-05-06 215 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