11
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?

Community
  • 1
  • 1
Blenderer
  • 682
  • 1
  • 5
  • 17

1 Answers1

27

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

Nikola
  • 2,093
  • 3
  • 22
  • 43
  • 1
    This doesn't make any sense. `list` looks to be the reserved word, not `List`. – vhs May 22 '17 at 09:26
  • 3
    @Josh H it makes sense: `Note: Function names are case-insensitive, though it is usually good form to call functions as they appear in their declaration.` from here: http://fr.php.net/manual/en/functions.user-defined.php – Nikola May 22 '17 at 11:04