2013-12-09 36 views
0

下面提到的代碼有什麼問題? 它是拋出解析錯誤 PHP解析錯誤:語法錯誤,意外'。',期待','或';'在第9行php常量在一個類的數據成員中

<?php 

class b { 
    const ABC = 'abc'; 
} 

class c extends b { 

    private $r = self::ABC ." d"; 
    function getABC() 
    { 
      echo $this->r; 
    } 
} 

$c = new c(); 
$c->getABC(); 
+0

你想要的是已經回答[這裏](http://stackoverflow.com/questions/6456939/php-accessing-parent-class-variable)。 – ThaMe90

回答

0

/home/gaurav/c.php你可以試試:

private $r = self::ABC; 
$r = $r . "d";  
0

得到的答案從http://www.php.net/manual/en/language.oop5.properties.php

This declaration may include an initialization, but this initialization must be a constant value--that is, it must be able to be evaluated at compile time and must not depend on run-time information in order to be evaluated. 

所以,在我的代碼自我:: ABC 「d」 是不恆定。

相關問題