multiple constructor question
| From: | jdavis | Date: | Thu, 08 Apr 2004 09:35:04 +0000 |
| Subject: | multiple constructor question | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-182802@lists.php.net to get a copy of this message | ||
Hello,
I have looked around for information on using multiple constructors
with OO PHP. I have found little, and from what I have seen I'm thinking
that it's not supported. Is this true. I wrote the code below to try
to emulate multiple constructors.. is this what everyone else does to
try to get the same functionality?
thanks,
--
jd@taproot.bz
"Bad spellers of the world untie!"
#!/usr/bin/php4
<?php
$args = $_SERVER['argv'];
if($args[0]){
$tc = new TestCon($args[1]);
}
else{
$tc = new TestCon();
}
class TestCon{
function TestCon($name = NULL){
if($name){
$this->doIt($name);
}
else{
$this->doIt("User");
}
}
function doIt($string){
echo "Hello $string\n";
}
}
?>