Php 创建一个数组,说它是一个对象?(S3)

Php 创建一个数组,说它是一个对象?(S3),php,amazon-s3,Php,Amazon S3,我创建了一个数组,如下所示: private $commands = []; 然后,我将以下内容添加到此数组中: $this->commands[] = $this->s3->getCommand('PutObject', [ 'Bucket' => xxx, 'Key' => xxx, 'Body' => xxx, 'ContentType' => xxx, 'ACL'

我创建了一个数组,如下所示:

private $commands = [];
然后,我将以下内容添加到此数组中:

$this->commands[] = $this->s3->getCommand('PutObject', [
        'Bucket' => xxx,
        'Key' => xxx,
        'Body' => xxx,
        'ContentType' => xxx,
        'ACL' => 'public-read'
    ]);
但当我尝试使用阵列时:

$pool = $this->s3->commandPool($this->s3, $this->commands);
我得到一个错误:

Argument 2 passed to Aws\AwsClient::getCommand() must be of the type array, object given, 
它抱怨一个对象,需要一个数组

我是否创建了错误的数组


(我使用的是PHP5.4,所以数组[]很好)

您使用的commandPool不正确。没有这样的方法,当您调用未定义的方法时,AwsClient会假定您正在尝试发送命令并在内部调用getCommand(),这就是为什么会出现错误

正确的方法是:

//at the top of your file
use Aws\CommandPool;

//and then
$pool = new CommandPool($this->s3, $this->commands);

错误是关于getCommand方法,而不是commandPool。您可以转储$this->s3的类名吗?即:$this->s3=AWS::createClient('s3');Im使用laravel facade:此方法可以返回不同类的对象。请执行dd(get_class($this->s3);dd是:“Aws\s3\S3Client”奇怪,我可以看到您正在将数组传递给getCommand。您确定这是导致错误的行吗?您不在其他地方调用getCommand吗?您应该在错误消息中包含文件名和行号。