PHP functions and custom methods
Moderator: General Moderators
PHP functions and custom methods
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?
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.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
- n00b Saibot
- DevNet Resident
- Posts: 1452
- Joined: Fri Dec 24, 2004 2:59 am
- Location: Lucknow, UP, India
- Contact:
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.Ree wrote:That's not the case of confusion or anything, the name fits the method purpose perfectly. But I understand your point.