9
class List {
  public function hello()
  {
    return "hello";
  }
}

$list = new List;

echo $list::hello();

エラーが発生します:

PHP Parse error: syntax error, unexpected 'List' (T_LIST), expecting identifier (T_STRING) in /home/WtGTRQ/prog.php on line 3

「List」を「Lizt」に変更すると、問題が修正されます。

悲しいことに、Php 関数は大文字と小文字を区別しないことを理解していますが、List オブジェクトを Lizt オブジェクトにしたくありません... クラスの名前を変更せずにこれを回避する方法はありますか?

4

1 に答える 1

23

Listは制限付きの PHP ワードです。

You cannot use any of the following words as constants, class names, function or method names.

http://www.php.net/manual/en/reserved.keywords.php

--

あなたの質問に答えるには、listクラス名を別のものに変更する必要があります。MyListCarListListing、など。

于 2013-09-13T20:03:20.403 に答える