0

采用RingCentral\SDK;

或者

require('/home/developer/workspace/ringcentral/demo/SDK.php');

与其使用 'use' - php 5.6 命令,不如使用 require - php 5.3 ?

SDK 类文件包含以下代码

class SDK
{

const VERSION = '0.5.0';

/** @var Platform */
protected $platform;

/** @var Context */
protected $context;

public function __construct($appKey, $appSecret, $server)
{

    $this->context = new Context();

    $this->platform = new Platform($this->context, $appKey, $appSecret, $server);

}

public function getPlatform()
{
    return $this->platform;
}

public function getSubscription()
{
    return new Subscription($this->context, $this->platform);
}

public function getContext()
{
    return $this->context;
}

}
4

2 回答 2

3

您必须要求一个自动加载器以允许 SPL 自动加载来解析使用语句:

// if you use Composer
require('vendor/autoload.php');
// or just require a PHAR
require('path-to-sdk/ringcentral.phar');

use RingCentral\SDK\SDK;

$sdk = new SDK(...);

您实际上可以省略 use 语句并使用完全限定的类名:

$sdk = new RingCentral\SDK\SDK(...);
于 2015-09-03T20:53:10.843 回答
1

require()用于要求另一个文件,而use用于使用来自另一个命名空间的类,因此这两个命令完全不同且不可比较。

在您的情况下,您将需要使用require(),除非您使用任何类型的自动加载,例如composer使类在您的文件中可用。

于 2015-08-31T05:05:07.167 回答