PHP functions and custom methods

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Ree
Forum Regular
Posts: 592
Joined: Fri Jun 10, 2005 1:43 am
Location: LT

PHP functions and custom methods

Post 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?
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post 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.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Last I tried it, it worked, however I wouldn't recommend replicating the names...
Ree
Forum Regular
Posts: 592
Joined: Fri Jun 10, 2005 1:43 am
Location: LT

Post by Ree »

That's not the case of confusion or anything, the name fits the method purpose perfectly. But I understand your point.
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post 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.
Post Reply