Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 863
Blenderer Avatar asked Sep 13 '13 19:09

Blenderer


1 Answers

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

like image 184
Nikola Avatar answered Sep 21 '22 20:09

Nikola