RE: [PHP] Function overloading bug?

From: Date: Tue, 19 Sep 2000 05:09:15 +0000
Subject: RE: [PHP] Function overloading bug?
References: 1  Groups: php.dev 
Request: Send a blank email to php-dev+get-33459@lists.php.net to get a copy of this message
Yeah, it's usefull. ie, class MySQL_DatabaseConnector { function ConnectToDatabase($server,$port,$user,$password) { // do the connection return $linkID; } function ConnectToDatabase($server,$port,$user,$password,$database) { $link = ConnectToDatabase($server,$port,$user,$password); mysql_select_db($database,$link); return $link; } } Now you can call either one, either passing it a database or not..you only have to remember to call "ConnectToDatabase()" in one form or another. You also have the case of Shape_Draw("Circle") // cicle which draw from m_radius; Shape_Draw("Circle",15); // circle w/radius 15 - sets m_radius to 15 and calls Shape_Draw("Circle"); Shape_Draw("Circle",15,2); // circle w/radius 15, linewidth 2. - Sets m_width = 2 and calls Shape_Draw("Circle",15); It has it's uses. Some are odd, but they are nice...you maintain a "chain" of methods instead of 15 differently named methods. Modify level 3, and all get the affect, instead of modifying each and every instance. It has it's uses.... -Szii At 12:46 AM 9/19/00 +0200, Steeve Lennmark wrote: >Maybe im stupid but should you really have two functions with the same name >in the class? >One takes 2 arguments, the other takes 3. > >> -----Original Message----- >> From: Szii [mailto:szii@sziisoft.com] >> Sent: den 18 september 2000 18:53 >> To: php-general@lists.php.net; php-dev@lists.php.net >> Subject: [PHP] Function overloading bug? >> >> >> Against the latest "release," the following does not work >> correctly for me... >> >> <?php >> class foo >> { >> function foo() >> { >> } >> >> function writeit($text,$length) >> { >> echo $text . " " . $length; >> } >> >> function writeit($text, $outText, $length) >> { >> echo $outText; >> $this->writeit($text,$length); // does not >> evaluate properly >> } >> >> } >> >> $a = new foo(); >> $a->writeit("hi","out",2); >> >> ?> >> >> Warning: Missing argument 3 for writeit() in >> /home/websites/sziisoft.com/index.php4 on line 18 >> >> Warning: Missing argument 3 for writeit() in >> /home/websites/sziisoft.com/index.php4 on line 18 >> >> Warning: Missing argument 3 for writeit() in >> /home/websites/sziisoft.com/index.php4 on line 18 >> >> Warning: Missing argument 3 for writeit() in >> /home/websites/sziisoft.com/index.php4 on line 18 >> >> Warning: Missing argument 3 for writeit() in >> /home/websites/sziisoft.com/index.php4 on line 18 >> >> Warning: Missing argument 3 for writeit() in >> /home/websites/sziisoft.com/index.php4 on line 18 >> >> Warning: Missing argument 3 for writeit() in >> /home/websites/sziisoft.com/index.php4 on line 18 >> >> Warning: Missing argument 3 for writeit() in >> /home/websites/sziisoft.com/index.php4 on line 18 >> >> <repeat forever> >> >> The 2nd writeit() makes a call to $this->writeit() and evaluates itself in >> the context of itself, instead of within the context of the class. ie, it >> tries to call itself instead of evaluating against the class, finding the >> "2 parameter method," and using it. This then generates a warning >> about an unused $outText and calls itself recursively, and infinitely. >> >> Anyone else noticed this? >> >> -Szii >> >> >> >> -- >> PHP General Mailing List (http://www.php.net/) >> To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net >> For additional commands, e-mail: php-general-help@lists.php.net >> To contact the list administrators, e-mail: php-list-admin@lists.php.net >

« previous php.dev (#33459) next »