ReflectionClass中的newInstanceArgs出错

时间:2011-06-16 07:31:44

标签: php zend-framework reflection

以下脚本完美无缺,

$transport = new Amazonses_App_Mail_Transport_AmazonSES(
        array(
            'accessKey' => '*******************',
            'privateKey' => '***********************'
            )
        );

但是,当它按如下方式转移时,会收到错误。

$mailConfig = array(
          'class' => 'Amazonses_App_Mail_Transport_AmazonSES',
          'args' => array( 'accessKey' => '*******************',
            'privateKey' => '***********************')
        );
 try {

        $args = ( !empty($mailConfig['args']) ? $mailConfig['args'] : array() );

        $r = new ReflectionClass($mailConfig['class']);


            $transport = $r->newInstanceArgs($args);


        if( !($transport instanceof Zend_Mail_Transport_Abstract) ) {
          $transport = false;
        } 
      } catch( Exception $e ) {

        $transport = false;
        throw $e;
      }

Amazonses_App_Mail_Transport_AmazonSES带有__construct。但是,未能返回$transport = $r->newInstanceArgs($args);

知道为什么吗?

1 个答案:

答案 0 :(得分:1)

您是否尝试过替换

$r = new ReflectionClass($mailConfig['class']);
$transport = $r->newInstanceArgs($args);

通过

$className = $mailConfig['class'];
$transport = new $className($args);

我认为它应该有用。