PHP Call-time pass-by-reference unavoidable?

前端 未结 2 511
醉话见心
醉话见心 2021-01-20 23:04

Given the following interface:

interface ISoapInterface {
  public static function registerSoapTypes( &$wsdl );
  public static function registerSoapOperatio         


        
相关标签:
2条回答
  • 2021-01-20 23:44

    From the call_user_func:

    Note that the parameters for call_user_func() are not passed by reference.

    To invoke static methods you can use Class::method() syntax, supplying a variable for the Class and/or method parts:

    $soapProvider = array( "FilePool", "UserList" );
    foreach( $soapProvider as $provider ) {
      $provider::registerSoapTypes($server->wsdl);
      $provider::registerSoapOperations($server);
    }
    
    0 讨论(0)
  • 2021-01-20 23:51

    While call_user_func does not pass parameters by reference, call_user_func_array can.

    $callback = array($provider, 'blahblahblah');
    call_user_func_array($callback, array( &$server ));
    

    The only real difference is that it expects an array of parameters instead of a list of parameters like call_user_func (similar to the difference between sprintf and vsprintf)...

    0 讨论(0)
提交回复
热议问题