尝试使用作曲家时出现意外的“使用"(T_USE) [英] unexpected 'use' (T_USE) when trying to use composer

查看:76
本文介绍了尝试使用作曲家时出现意外的“使用"(T_USE)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我正在尝试使用coinbase API.我正在尝试进行简单的测试,以查看是否可以使它正常工作,但是我遇到了各种各样的作曲家错误.

So, I am trying to use the coinbase API. I'm attempting a simple test to see if I can make it work, but I'm getting various composer errors.

当前,我对于此代码的使用变得出乎意料:

Currently, I am getting unexpected t 'use' for this code:

            use Coinbase\Wallet\Client;
            use Coinbase\Wallet\Configuration;

            $apiKey = 'public';
            $apiSecret = 'private';
            $configuration = Configuration::apiKey($apiKey, $apiSecret);
            $client = Client::create($configuration);
            $spotPrice = $client->getSpotPrice();
            echo $spotPrice;

那么,我的use语句放在错误的位置了吗?香港专业教育学院尝试在索引函数和类之外的他们.两者都产生了完全不同的结果集.

So, are my use statements in the wrong place? Ive tried them outside the index function and outside the class. Both yield completely different sets of results than this.

在Keks类之外,我得到

Outside of the Keks class, I get

致命错误:找不到"Coinbase \ Wallet \ Configuration"类 /home/content/61/11420661/html/beta/application/controllers/keks.php 在第15行

Fatal error: Class 'Coinbase\Wallet\Configuration' not found in /home/content/61/11420661/html/beta/application/controllers/keks.php on line 15

在类内部但在index()函数外部

And inside the class but outside the index() function I get

致命错误:在第4行的>/home/content/61/11420661/html/beta/application/controllers/keks.php中找不到特征'Coinbase \ Wallet \ Client'

Fatal error: Trait 'Coinbase\Wallet\Client' not found in >/home/content/61/11420661/html/beta/application/controllers/keks.php on line 4

composer.json可能有问题吗?

Is there something wrong in my composer.json maybe?

完整的控制器在这里: http://pastebin.com/4BjPP6YR

The full controller is here: http://pastebin.com/4BjPP6YR

推荐答案

您不能在使用它的地方使用"use".

You cannot use "use" where you are using it.

"use"关键字位于类定义的前面,以将其他类/接口/特征导入其自己的名称空间,或者位于类内部(但不在方法内部)以向该类添加特征. /p>

The "use" keyword is either in front of a class definition to import other classes/interfaces/traits into it's own namespace, or it is inside the class (but not inside a method) to add traits to the class.

<?php
namespace Foo;

use Different\Class; // use can go here

class Bar {
  use TraitCode; // use can go here

  public function baz() {
    $this->traitFunction('etc');
    // use CANNOT go here
  }
}

这篇关于尝试使用作曲家时出现意外的“使用"(T_USE)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆