문제

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

$list = new List;

echo $list::hello();

Gives Error:

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

Changing "List" to "Lizt" fixes the issue.

I sadly understand that Php functions are case-insensitive, but I really don't want to make a List object a Lizt object... Is there some way to circumvent this without renaming my class?

도움이 되었습니까?

해결책

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..

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top