multiple constructor?

liunx

Guest
if a build a class and i want to make 3 constructor:

1rt constructor: take one argument
2nd constructor: take 2 argument
3rd constructor: take 3 argument

and i want the first constructor to call the constructor 3
and i want the second constructor to call the constructor 3 too.

someting like this:

class User
{
...
public function User($UserID) : this->($UserID, NULL, NULL);
public function User($UserID, $UserName) : this->($UserID, $UserName, NULL);
public function User($UserID, $UserName, $Adress)
{
....
}

how do i do something like this in php5, i was looking for documentation on this and still looking for it :(

And what about using "public function __construct" for multiple constructor?
Can someone help me with the syntax using multiple constructor in php5?
I would realy appreciate.
thx guysstill need help :confused:I found what I was looking for there:
<!-- m --><a class="postlink" href="http://www.dbforums.com/t1095437.html">http://www.dbforums.com/t1095437.html</a><!-- m -->
:bemused:if you want to emulate method overloading, here's one way (assuming each overload has a different number or parameters)...

Create a method with no parameters.
Inside that method, use a combination of func_get_arg(), func_get_args(), and func_num_args() to determine the signature and call the appropriate (private) method, or branch the method code as needed.
 
Back
Top