尝试使用作曲家时

尝试使用作曲家时

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

问题描述

限时删除!!

所以,我正在尝试使用 coinbase API.我正在尝试一个简单的测试,看看我是否可以让它工作,但是我遇到了各种作曲家错误.

目前,我对这段代码意外地使用"了:

 使用 Coinbase\Wallet\Client;使用 Coinbase\Wallet\Configuration;$apiKey = '公共';$apiSecret = '私人';$configuration = Configuration::apiKey($apiKey, $apiSecret);$client = Client::create($configuration);$spotPrice = $client->getSpotPrice();回声 $spotPrice;

那么,我的 use 语句是不是放错地方了?我已经在索引函数之外和课堂之外尝试过它们.两者都产生了与这完全不同的结果集.

在 Keks 课程之外,我得到

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

在类内但在 index() 函数外我得到

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

我的 composer.json 可能有问题吗?

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

解决方案

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

use"关键字要么位于类定义前面以将其他类/接口/特征导入到它自己的命名空间中,要么位于类内部(但不在方法内部)以向类添加特征.

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;

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.

Outside of the Keks class, I get

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

Is there something wrong in my composer.json maybe?

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

解决方案

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

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
  }
}

这篇关于意外&amp;#39;use&amp;#39;(T_USE) 尝试使用作曲家时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 19:27