OR you could control ur method and have optional arguments in ur argument list and decide what to do according to that. e.g. public function _construct($param1=0, $param2="", $param3=null) { if($param1) .... if($param2) .... if($param3) .... } $obj=new className(1); //Or $obj=new className(1,"hello"); //Or $obj=new className(0,"","some_value"); Bottom Line: Optional arguments might be a workaround lack of polymorphism sometimes ! On Sun, 24 Oct 2004 22:59:25 +0200, Daniel Schierbeck <dasch@xxxxxxxxxx> wrote: > Walter Wojcik wrote: > > > > I want to override the constructor for a class i am writing but when i try it says i cant redefine it. Is the a whay to have two (or more) functions with the same name that accept different agrumants and calls the right one based on the arguments (it would have to be based on number of args because of the loose typing of php.). > > > > > > "Knowledge is power, Those who have it must share with those who don't" > > -Walter Wojcik > > > > > > > > > > --------------------------------- > > Do you Yahoo!? > > vote.yahoo.com - Register online to vote today! > No. But you can use func_num_args() to decide how many arguments the > constructor (or any other function) was called with, and then make your > decisions. > > class Foo > { > public function __construct () > { > if (func_num_args() > 2) { > $this->one(func_get_args()); > } else { > $this->two(func_get_args()); > } > } > > protected function one ($args) > { > // foo > } > > protected function two ($args) > { > // bar > } > } > > -- > Daniel Schierbeck > > Help spread Firefox (www.getfirefox.com): > http://www.spreadfirefox.com/?q=user/register&r=6584 > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- M.Saleh.E.G 97150-4779817 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php