Nieuw lid |
|
owja, hetgeen ik al geprobeerd heb maar dus eig niet voldoet:
class Hoge {
public function __construct(){
$num = func_num_args();
$args = func_get_args();
switch($num){
case 0:
$this->__call('__construct0', null);
break;
case 1:
$this->__call('__construct1', $args);
break;
case 2:
$this->__call('__construct2', $args);
break;
case 3:
$this->__call('__construct3', $args);
break;
default:
throw new Exception();
}
}
public function __construct0(){
echo "constructor 0" . PHP_EOL;
}
public function __construct1($a){
echo "constructor 1: " . $a . PHP_EOL;
}
public function __construct2($a, array $hoge){
echo "constructor 2: " . $a . PHP_EOL;
var_dump($hoge);
}
public function __construct3(A $a, A $b, C $c){
echo "constructor 3: " . PHP_EOL;
var_dump($a, $b, $c);
}
private function __call($name, $arg){
return call_user_func_array(array($this, $name), $arg);
}
}
class Hoge { public function __construct(){ switch($num){ case 0: $this->__call('__construct0', null); break; case 1: $this->__call('__construct1', $args); break; case 2: $this->__call('__construct2', $args); break; case 3: $this->__call('__construct3', $args); break; default: throw new Exception(); } } public function __construct0(){ echo "constructor 0" . PHP_EOL ; } public function __construct1($a){ echo "constructor 1: " . $a . PHP_EOL ; } public function __construct2 ($a, array $hoge){ echo "constructor 2: " . $a . PHP_EOL ; } public function __construct3(A $a, A $b, C $c){ echo "constructor 3: " . PHP_EOL ; } private function __call($name, $arg){ } }
|