PHP5实现构造方法重载一法
时间:2007-06-29 来源:liuxingyuyuni
?php
class OverloadTest{
function __construct()
{
$arr=func_get_args();
switch(func_num_args())
{
case 1:
$this->cons1($arr[0]);
break;
case 2:
$this->cons2($arr[0],$arr[1]);
break;
}
}
function cons1($var)
{
echo "cons1(".$var.") called.";
}
function cons2($var1,$var2)
{
echo "cons2(".$var1.",".$var2.") called.";
}
}
$foo = new OverloadTest('x');
$foo2 = new OverloadTest('x',"y");
?>
相关阅读 更多 +
排行榜 更多 +