[PHP-DEV] RE: [PHP] Function overloading bug? From: Szii (szii <email protected>)
Date: 09/19/00

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 <email protected>]
>> Sent: den 18 september 2000 18:53
>> To: php-general <email protected>; php-dev <email protected>
>> 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 <email protected>
>> For additional commands, e-mail: php-general-help <email protected>
>> To contact the list administrators, e-mail: php-list-admin <email protected>
>

-- 
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, e-mail: php-dev-unsubscribe <email protected>
For additional commands, e-mail: php-dev-help <email protected>
To contact the list administrators, e-mail: php-list-admin <email protected>