note 121511 deleted from language.oop5.overloading by cmb

From: Date: Sun, 18 Aug 2019 08:25:52 +0000
Subject: note 121511 deleted from language.oop5.overloading by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-211901@lists.php.net to get a copy of this message
Note Submitter: niki_arsov at mail dot bg ---- <?php class Overload { function __call($function, $params) { $function = '_' . $function; $this->$function($params); } public function _show($params ) { $res = ''; switch (count($params)) { case 0: $res = sprintf("method show with %d arg", 0); break; case 1: $res = sprintf("method show with %d arg: %s", 1, $params[0]); $res .= $this->getType($params[0]); break; case 2: $res = sprintf("method show with %d arg: %s, %s", 2, $params[0], $params[1]); $res .= $this->getType($params[0]); $res .= $this->getType($params[1]); break; default: # code... break; } print $res . "\n"; } private function getType($arg) { $res = ''; switch (gettype($arg)) { case 'double': $res .= ' - double'; break; case 'string': $res .= ' - string'; break; case 'integer': $res .= ' - integer'; break; default: $res .= ' - '; break; } return $res; } } $class = new Overload; $class->show(); $class->show(12); $class->show(12.5); $class->show('test'); $class->show('test', 1.5); ?> Will output: method show with 0 arg method show with 1 arg: 12 - integer method show with 1 arg: 12.5 - double method show with 1 arg: test - string method show with 2 arg: test, 1.5 - string - double

« previous php.notes (#211901) next »