这是方法重载,php4下,用以下的方法模拟方法重载。class Myclass { function Myclass() { $name="Myclass".func_num_args(); $this->$name(); //Note that $this->$name() is usually wrong but here //$name is a string with the name of the method to call. } function Myclass1($x) { code; } function Myclass2($x,$y) { code; } } $obj1=new Myclass(1); //Will call Myclass1 $obj2=new Myclass(1,2); //Will call Myclass2
function Myclass() {
$name="Myclass".func_num_args();
$this->$name();
//Note that $this->$name() is usually wrong but here
//$name is a string with the name of the method to call.
} function Myclass1($x) {
code;
}
function Myclass2($x,$y) {
code;
}
} $obj1=new Myclass(1); //Will call Myclass1
$obj2=new Myclass(1,2); //Will call Myclass2