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



Reply via email to