Page 1 of 1
PHP functions and custom methods
Posted: Thu Sep 29, 2005 12:36 pm
by Ree
Is it ok to use the same names of PHP native functions in class methods? For example, I need to have a method named 'getType()' in my class. Will $obj->getType() use the object's method defined by me, or will PHP try to use its own function gettype() in some way?
Posted: Thu Sep 29, 2005 12:45 pm
by pickle
Don't duplicate built in functions. I'm betting the file won't even parse if you do. Besides that though, it'd bad form and would be very confusing to third parties (or even yourself 6 months down the road), to see that function call and not know which one you're referring to.
Posted: Thu Sep 29, 2005 1:16 pm
by feyd
Last I tried it, it worked, however I wouldn't recommend replicating the names...
Posted: Fri Sep 30, 2005 6:25 am
by Ree
That's not the case of confusion or anything, the name fits the method purpose perfectly. But I understand your point.
Posted: Fri Sep 30, 2005 6:48 am
by n00b Saibot
Ree wrote:That's not the case of confusion or anything, the name fits the method purpose perfectly. But I understand your point.
duplicating inbuilt function names is not recommended but inside a class definition if you think it helps you define the purpose exactly, use it at your will since it will be referenced as $obj->getType which doesn't seem create any confusion imo.