【问题标题】:Uncaught Error: Class 'Google\AdsApi\Examples\AdWords\v201809\Reporting\DOMDocument' not found未捕获的错误:找不到类“Google\AdsApi\Examples\AdWords\v201809\Reporting\DOMDocument”
【发布时间】:2018-10-04 13:11:05
【问题描述】:

我安装了 php-xml,它与其他 php 文件一起运行良好,使用以下代码在网站上显示 xml:

$doc = new DOMDocument();
$doc->loadXML(html_entity_decode($xml), LIBXML_NOXMLDECL);
echo $doc->saveXML();

但它不适用于 Google AdWords Report API。它显然与 namespace Google\AdsApi\Examples\AdWords\v201809\Reporting; 有关。我不熟悉 PHP,想知道如何让这个 DOMDocument 在 Reporting 命名空间内工作。谢谢。

【问题讨论】:

  • 在类名前加一个斜杠:$doc = new \DOMDocument(); 这将强制它不使用当前的命名空间。
  • 非常感谢您的及时回复。这当然解决了问题。

标签: php xml domdocument google-ads-api


【解决方案1】:

您需要在DOMDocument 之前添加反斜杠\ 以从全局命名空间加载类。否则 php 会在您当前的命名空间中搜索 DOMDocument 类。

如果您需要有关此的更多信息,您可能需要查看php documentation for global namespaces:

$doc = new \DOMDocument();

【讨论】:

    猜你喜欢
    • 2020-06-21
    • 2023-03-24
    • 1970-01-01
    • 2017-05-21
    • 2020-10-02
    • 2020-11-10
    • 2021-12-03
    • 2020-04-21
    相关资源
    最近更新 更多