Page 1 of 1
is method overloading possible in php?
Posted: Wed Sep 28, 2005 2:17 am
by saumya
Hi guys,
Is it possible to overload a method in php like in java? I mean how to make a method overloaded?
thanking youi
saumya
Posted: Wed Sep 28, 2005 3:24 am
by patrikG
Posted: Wed Sep 28, 2005 4:14 am
by saumya
thanks a lot.
Posted: Wed Sep 28, 2005 6:48 am
by sweatje
What is called "overloading" in PHP is significantly different from what overloading means in most other languages. Overloading typically means having different signatures for the same named method (or function) and having those different signature react appropriatly. This often worked off of type hints (type fatals actually

in php ) in statically typed languages. In PHP, you would have to encode all of the possible signatures and behaviors within the same function body. You have a lot of flexibility: default parameters, checking parameter types (is_numeric, is_string, is_object), checking class (is_a, instance_of, get_class), duck typing, and allowing for variable parameter lists (funct_num_args, funct_get_args).
HTH
Posted: Wed Sep 28, 2005 7:01 am
by saumya
thank you.
Yes,you are right.
this is the thing i got to know, when i read the article given by patrikG.
here overloading does something else. One has to write all the methods to deal with different type of datas and number of datas manually.WEll, no problem.I was just seeking the info. Now i know i have to write it manually, so ai will go about it calmly.Or else i would have been searching for how to write an overloaded method.
thanking you
saumya
Posted: Wed Sep 28, 2005 12:01 pm
by Skara
Yeah, I learned php before C++, so C++ always bugs me that you actually have to write a function twice. ^^;