Pergunta

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?

Foi útil?

Solução

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

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top