note 34921 deleted from ref.overload by sobak
| From: | sobak@php.net | Date: | Tue, 22 Nov 2016 03:48:42 +0000 |
| Subject: | note 34921 deleted from ref.overload by sobak | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-207441@lists.php.net to get a copy of this message | ||
Note Submitter: fabiostt[X_AT_X]libero[X_DOT_X]it
----
This extension has not much to do with overloading as we know it in Java or C++
We can sort of mimic overloading using call_user_func_array()
<?php
class OverloadTest{
var $message ;
function OverloadTest(){
$numArgs = func_num_args() ; //number of args
$args = func_get_args() ; //array containing args
call_user_func_array( array( &$this, 'OverloadTest'.$numArgs), $args) ;
}
function overloadTest0(){
$this->message = 'There are no args' ;
}
function overloadTest1($arg){
$this->message = 'There\'s just one arg, its value is '.$arg ;
}
function overloadTest2($arg1, $arg2){
$this->message = 'There are 2 args, their values are '.join( func_get_args(),
', ') ;
}
function getMessage(){
return($this->message) ;
}
}//end class
$x = new OverloadTest('fooA', 'fooB') ;
echo( $x->getMessage() ) ;
?>