2010-11-24 13 views
5

私はこのエラーを取得しています:この(簡体字)のコードで奇妙なパースエラー変数

Parse error: syntax error, unexpected '.', expecting ',' or ';' in /var/(...)/config.php on line 5

<?php 

class Config 
{ 
    public static $somevar = "Date: " . date('Y'); 
} 

?> 

を、私は、これは有効なPHPだと思ったが、私はないと思います...私はここで間違って何をしていますか?ありがとう!解析時にこれが評価されるためManual

Like any other PHP static variable, static properties may only be initialized using a literal or constant; expressions are not allowed. So while you may initialize a static property to an integer or array (for instance), you may not initialize it to another variable, to a function return value, or to an object.

答えて

5

Like any other PHP static variable, static properties may only be initialized using a literal or constant; expressions are not allowed. So while you may initialize a static property to an integer or array (for instance), you may not initialize it to another variable, to a function return value, or to an object.

クラス定義の後

Config::$somevar = "Date: " . date('Y'); 

を書いてみてください。

+1

ありがとうございました! –