PHP致命错误:未捕获错误:在test.php中找不到类'Aws \ Common \ Aws'

问题描述:

I installed AWS PHP SDK v3 based on http://docs.aws.amazon.com/aws-sdk-php/v3/guide/getting-started/installation.html using composer method. Tried a simple example but getting this error:

PHP Fatal error:  Uncaught Error: Class 'Aws\Common\Aws' not found in test.php

Code:

<?php

// Include the SDK using the Composer autoloader
require 'vendor/autoload.php';

use Aws\Common\Aws;

$aws = Aws::factory('./cfg.php');

/* CODE BELOW WORKS FINE BY ITSELF
$s3 = new Aws\S3\S3Client([
    'version' => 'latest',
    'region'  => 'us-west-1',
    'credentials' => [
        'key'    => '***',
        'secret' => '***'
    ],
]);

$result = $s3->listBuckets();

foreach ($result['Buckets'] as $bucket) {
    // Each Bucket value will contain a Name and CreationDate
    echo "{$bucket['Name']} - {$bucket['CreationDate']}
";
}
*/
?>

My PHP version:

PHP 7.1.0alpha2 (cli) (built: Jun 27 2016 22:39:02) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.1.0-dev, Copyright (c) 1998-2016 Zend Technologies

I tried including aws.phar instead but still did not work.

我安装了基于 http://docs.aws.amazon.com/aws-sdk-php/v3/guide/getting- 使用composer方法启动/ installation.html 。 尝试了一个简单的例子,但得到了这个错误: p>

  PHP致命错误:未捕获错误:在test.php 
  code>中找不到类'Aws \ Common \ Aws'   pre> 
 
 

代码: p>

 &lt;?php 
 
 //使用Composer自动加载器
require'供应商/自动加载包含SDK  .php'; 
 
use Aws \ Common \ Aws; 
 
 $ aws = Aws :: factory('./ cfg.php'); 
 
 / *下面的代码工作效果很好
 $  s3 =新的Aws \ S3 \ S3Client([
'版本'=&gt;'最新',
'区域'=&gt;'us-west-1',
'凭证'=&gt; [
'  key'=&gt;'***',
'secret'=&gt;'***'
],
]); 
 
 $ result = $ s3-&gt; listBuckets(); \  n 
foreach($ result ['Buckets'] as $ bucket){
 //每个Bucket值将包含一个Name和CreationDate 
 echo“{$ bucket ['Name']}  -  {$ bucket ['CreationDate'  ]} 
“; 
} 
 * / 
?&gt; 
  code>  pre> 
 
 

我的PHP版本: p>

   PHP 7.1.0alpha2(cli)(建于2016年6月27日22:39:02)(NTS)
版权所有(c)1997-2016 PHP Group 
Zend Engine v3.1.0-dev,Copyright(c)1998  -2016禅 d Technologies 
  code>  pre> 
 
 

我尝试包括aws.phar,但仍然无效。 p> div>

Not sure what ./cfg.php contains, but if you follow your commented code.

You could use Aws\Kms\KmsClient and do something like:

require 'vendor/autoload.php';

$client = Aws\Kms\KmsClient::factory(/*Config Array or Guzzle Http Client*/);

$result = $client->listKeys();

Just so you know, Aws\Kms\KmsClient is nearly the exact same client as Aws\AwsClient

Further info on that config needed to create the client