Reserved PHP Function: list()?

pr0gr4mm3r's picture

He has: 1,502 posts

Joined: Sep 2006

I am having trouble having a method in a class called "list()". PHP gives me a parse error, and I have to name it something else. Why is this, and is there a way around it?

Greg K's picture

He has: 2,145 posts

Joined: Nov 2003

See http://us2.php.net/manual/en/reserved.keywords.php

These words have special meaning in PHP. Some of them represent things which look like functions, some look like constants, and so on--but they're not, really: they are language constructs. You cannot use any of the following words as constants, class names, function or method names. Using them as variable names is generally OK, but could lead to confusion.

If it is a method that will only be used by the class, then try an alternative like _list(), otherwise use a similar meaning or longer one:

describe()
listItems()

pr0gr4mm3r's picture

He has: 1,502 posts

Joined: Sep 2006

Well that's a bummer. This class I'm writing is working with a proprietary desktop application, and I wanted to make the API calls match up with the methods. So much for that idea. Smiling

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.