我有以下内容:
class Delegator
{
public $Create;
public $Update;
public $Delete;
}
// Inside controller 1
$delegator = new Delegator();
$delegator->Create = function(){ /**/ };
$delegator->Update = function(){ /**/ };
$delegator->Delete = function(){ /**/ };
InvokeAction( $delegator );
//-------------------
// Inside controller 2
function InvokeAction( Delegator &$delegator )
{
switch( $something )
{
case "create":
$delegator->Create(); // Says Create method is undefined.
break;
}
}
//-------------------
在Invoke动作函数中,它调用Create变量就好像它是一个函数,但它看不到它?我有什么想法?
ANSWER ----------------
call_user_func( $delegator->Create, /* parameters go here if needs be */ );