At 11:57 25.11.2002, Dan Field said:
--------------------[snip]--------------------
>is it doable?
>
>class myClass {
>       var $myInt;
>
>       // default constructor
>       function myClass() {
>       }
>       
>       // overloaded constructor
>       function myClass($newInt) {
>               $this->myInt = $newInt;
>       }
>}
--------------------[snip]-------------------- 

At least not with PHP 4.2:

<?php
class A  {
        function A() {
                echo "default constructor A()\n";
        }
        function A($string) {
                echo "overloaded constructor A($string)\n";
        }
}

$a1 = new A();
$a2 = new A('Test');

?>

Results in:
    overloaded constructor A()
    overloaded constructor A(Test)
thus bypassing the default constructor and calling the overloaded
constructor both times.

What you might do to distinguish which "overload" has been called:

    function A($string=null) {
        if (!isset($string))
            echo "Default constructor A()\n";
        else
            echo "Overloaded constructor A($string)\n";
    }

Hope this helps,

-- 
   >O     Ernest E. Vogelsinger
   (\)    ICQ #13394035
    ^     http://www.vogelsinger.at/



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to