Trying to make a class called “List”, but the list() function is breaking it

前端 未结 1 846
小蘑菇
小蘑菇 2020-12-11 16:44
class List {
  public function hello()
  {
    return \"hello\";
  }
}

$list = new List;

echo $list::hello();

Gives Error:

相关标签:
1条回答
  • 2020-12-11 17:39

    List is a restricted PHP word.

    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

    --

    To answer your question, you will have to change your list class name to something else. MyList, CarList, Listing, etc..

    0 讨论(0)
提交回复
热议问题