NYCPHP Meetup

NYPHP.org

[nycphp-talk] Method overloading

Kenneth Downs ken at secdat.com
Fri Dec 14 14:31:49 EST 2007


Ben Sgro wrote:
> Yup,
>
> I figured I'd go down that path. It just adds extra logic, because in one
> case the 1st arg is an array, in the other its a bunch of strings.

Yeah, I just handle that by putting a trap in, if the argument is an 
array I leave it alone but if it is a string I explode it.

>
> Ok, so you the answer is "no", you can't do method overloading in php?

AFAIK, Yes, the answer is no :)

>
> - Ben
>
> Kenneth Downs wrote:
>> Ben Sgro wrote:
>>> Hello,
>>>
>>> Reading a java book on OOP, I wanted to do this in php:
>>>
>>> class foo
>>> {
>>>    public function bar($string){...}
>>>    public function bar($string, $int, $array) {...}
>>> }
>>>
>>>
>>> It should provide different "signatures" and allow method 
>>> overloading...
>>> Why not in php?
>>
>> I can't answer the "why", but you can get to the same place by 
>> providing default values:
>>
>> class foo {
>>    public function bar ($string,$int=0,$array=array()) { ... }
>> }
>>
>>>
>>> Is that not built in?
>>>
>>> - Ben
>>> _______________________________________________
>>> New York PHP Community Talk Mailing List
>>> http://lists.nyphp.org/mailman/listinfo/talk
>>>
>>> NYPHPCon 2006 Presentations Online
>>> http://www.nyphpcon.com
>>>
>>> Show Your Participation in New York PHP
>>> http://www.nyphp.org/show_participation.php
>>
>>
> _______________________________________________
> New York PHP Community Talk Mailing List
> http://lists.nyphp.org/mailman/listinfo/talk
>
> NYPHPCon 2006 Presentations Online
> http://www.nyphpcon.com
>
> Show Your Participation in New York PHP
> http://www.nyphp.org/show_participation.php


-- 
Kenneth Downs
Secure Data Software, Inc.
www.secdat.com    www.andromeda-project.org
631-689-7200   Fax: 631-689-0527
cell: 631-379-0010




More information about the talk mailing list