mononym
mononym

Reputation: 2636

Can I remove a php function?

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?

Upvotes: 0

Views: 2653

Answers (3)

Pascal MARTIN
Pascal MARTIN

Reputation: 400932

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()`][5] 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 !

Upvotes: 6

Mark Baker
Mark Baker

Reputation: 212412

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?

Upvotes: 5

user229044
user229044

Reputation: 239260

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.

Upvotes: 10

Related Questions