[PHP] Core function names as class methods

Soldato
Joined
18 Oct 2002
Posts
5,464
Location
London Town
Just a quick query regarding any possible implications of naming a class method the same as a PHP function (PHP5), other than potentially confusing client code.

e.g. Logger::log() named the same as PHP's log().

As far as I can see there aren't any problems with something like that, but was after some confirmation.
 
Thanks for the reply. The code is only going to be interacted with by my fellow developers, so syntax won't be a problem (I hope!). I guess context is important too - a method called log() in a class with mathematical functionality would be more confusing than one dealing with logging of messages.

I agree it's better to avoid it if possible, just sometimes it's nicer to use a 'natural' function name than an alternative one dug out of the thesaurus.
 
Definitely, that makes a lot of sense. I hadn't really considered it that way.
The doSomething() style of function description is the convention I normally follow, but I was tempted by the snappiness of log() in this case. A name like writeLog() it will be :).
 
Back
Top Bottom