Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
484 views
in Technique[技术] by (71.8m points)

php - unexpected 'use' (T_USE) when trying to use composer

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 CoinbaseWalletClient;
            use CoinbaseWalletConfiguration;

            $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

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

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

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

Is there something wrong in my composer.json maybe?

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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 DifferentClass; // use can go here

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

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...