0

I would like to use:

function list(args);

but list is a reserved word.

Can I remove the list function from PHP, disable it, or otherwise?

user229044
  • 232,980
  • 40
  • 330
  • 338
mononym
  • 2,606
  • 6
  • 26
  • 27
  • 1
    No but if you press Ctrl+H in your editor you can replace all instances of **list** with, say **list_** in your project. – Hossein Mar 17 '11 at 17:28
  • Dup http://stackoverflow.com/questions/2302771/is-it-possible-to-escape-a-method-name-in-php-to-be-able-to-have-a-method-name http://stackoverflow.com/questions/5298507/php-reserved-names-functions – AlfaTeK Mar 17 '11 at 17:31
  • yeah i'm all about the epic, thanks for the comment – mononym Mar 17 '11 at 17:40

3 Answers3

10

No, you can't, nor should you want to. Redefining built-in functions is a Bad Thing, especially something as fundamental as list, which isn't a function at all - it's a language construct.

All you can do is come up with a unique name for your function.

user229044
  • 232,980
  • 40
  • 330
  • 338
6

In a normal situation, no, you cannot remove a function.

Using the runkit extension (which I've virtually never seen installed on a server -- and absolutely never on a production server !), you'd have the runkit_function_remove() function, that could help.

Same with other debugging extensions, such as APD, which provides the override_function(), btw.


With PHP >= 5.3 and namespaces, you could also re-define a function, inside your own namespace, that could sort of replace the one of the global namespace.


But note that list() is not a function : it is a language construct -- and, as such, it doesn't behave like functions...


As a sidenote : even if possible (and/or when possible), replacing an existing function with your own, that doesn't do the same thing, is not a good idea : people reading your code, maintaining it, will have more difficulties understanding what it does !

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
Pascal MARTIN
  • 395,085
  • 80
  • 655
  • 663
5

You can only rename/remove core functions using the runkit or APD extensions. list isn't actually a function, but a language construct, so you can't rename it even with those extensions.

You should really be using a better choice of names for your own functions... list() isn't particularly meaningful. list what?

Mark Baker
  • 209,507
  • 32
  • 346
  • 385
  • list isn't meaningful!? are you joking. what about /users/list/ as a url – mononym Mar 17 '11 at 17:42
  • 1
    /users/list/ as a url gives you an indication of what is being listed (users)... simply calling a function list() without context tells you nothing about what it lists – Mark Baker Mar 17 '11 at 17:43