如何在 Yii 中实例化另一个命名空间中的对象?

How do I instantiate an object in another namespace in Yii?

我有以下

<?php
namespace app\commands;
use \Keyword as GoogleKeyword;

class KwController extends \yii\console\Controller
{

  public function actionTest() {
      $keyword = new GoogleKeyword();
  }

报错

$ yii kw/test
PHP Fatal error:  Class 'Keyword' not found in /cygdrive/c/Users/Chloe/workspace/project/commands/KwController.php on line 69
PHP Fatal Error 'yii\base\ErrorException' with message 'Class 'Keyword' not found'

in /cygdrive/c/Users/Chloe/workspace/project/commands/KwController.php:69

Stack trace:
#0 [internal function]: yii\base\ErrorHandler->handleFatalError()
#1 {main}

我不明白,因为它曾经有效。

这是定义的地方

$ grep Keyword vendor/googleads/googleads-php-lib/src/Google/Api/Ads/AdWords/v201509/CampaignCriterionService.php
if (!class_exists("Keyword", false)) {
  class Keyword extends Criterion {
    const XSI_TYPE = "Keyword";

这里是composer.json

{
    "require": {
        "googleads/googleads-php-lib": "~6.5"

以下任一方法都有效

use \Keyword as GoogleKeyword; // name clash
require 'vendor/googleads/googleads-php-lib/src/Google/Api/Ads/AdWords/v201509/CampaignCriterionService.php'; # for Keyword

  public function actionTest() {
    $gaw = new GoogleAdWords();
    $user = $gaw->getUser(); # returns an AdWordsUser
    $campaignCriterionService = $user->GetService('CampaignCriterionService', ADWORDS_VERSION);
    $keyword = new GoogleKeyword();

我认为 GetService 会自行加载魔法。