note 34921 added to ref.overload

From: Date: Tue, 12 Aug 2003 06:56:59 +0000
Subject: note 34921 added to ref.overload
Groups: php.notes 
Request: Send a blank email to php-notes+get-53934@lists.php.net to get a copy of this message
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() ) ; ?> ---- Manual Page -- http://www.php.net/manual/en/ref.overload.php Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+34921 Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+34921&report=yes Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+34921&report=yes

« previous php.notes (#53934) next »