...

View Full Version : How to call a class function from another class using the parameters given



telmessos
11-12-2012, 03:35 PM
Hi,

I have a PHP file calling the following function of the following class


<?
$transfer = new transfer();
$transfer->bolge_yukle();
?>


Is it possible to send the class transfer() and function bolge_yukle() to another class as a parameter to be called from there?

For example:

I have function of general.php which includes many general form functions but sometimes I would like to call the custom class and functions. I want to a add a function to General.php to call the custom class and functions. e.g:


$custom_func1 = new general_form();
$general_form->call_custom_func('transfer','bolge_yukle');

I hope I could explain the situation.

Kindest regards
telmessos.

kbluhm
11-12-2012, 03:45 PM
Like this?


class general_form
{

public function call_custom_func( $class, $func )
{
$class = new $class;
return $class->$func();
}

}


Of course there are more complex methods like reflection:


class general_form
{

public function call_custom_func( $class, $func )
{
$class = new ReflectionClass( $class );
$object = $class->newInstance();
return $class->getMethod( $func )->invoke( $object );
}

}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum