如何在另一个文件的函数中传递名称空间?

时间:2018-11-15 16:00:09

标签: php function namespaces microsoft-graph global

这是我的代码以及正在运行的代码:

// index.php

require "/var/www/functions.php";
use Microsoft\Graph\Graph;
use Microsoft\Graph\Model;
$microsoftGraph = new Graph();

test();



// functions.php

function test($microsoftGraph) {
    $create = $microsoftGraph->createRequest('POST', $create)
    ->setReturnType(Model\Event::class) // This is where I'm having a problem
    ->execute();
}

错误提示:

  

PHP致命错误:未捕获的错误:在...中找不到类'Event'。


但是... ,如果我将use放在我的functions.php中,则可以正常工作:

use Microsoft\Graph\Graph;
use Microsoft\Graph\Model;

function test($microsoftGraph) {
    $create = $microsoftGraph->createRequest('POST', $create)
    ->setReturnType(Model\Event::class) // This is where I'm having a problem
    ->execute();
}

但是我如何“通过”或不将use放入functions.php文件中?

0 个答案:

没有答案