注意:使用未定义的常量STDOUT-假定为"STDOUT" [英] Notice: Use of undefined constant STDOUT - assumed 'STDOUT'

查看:454
本文介绍了注意:使用未定义的常量STDOUT-假定为"STDOUT"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Xampp中设置Amazon Aws Php SDK.

I am trying to set up Amazon Aws Php SDK in Xampp.

安装SDK之后,我尝试使用以下代码从Amazon S3下载存储桶.

After installing the SDK, I am trying to download a bucket from Amazon S3, using the following code.

<?php

error_reporting(-1);
ini_set('display_errors', 'on');

include_once ('aws/aws-autoloader.php');
use Aws\S3\S3Client;

$client = S3Client::factory(array(
     'key'    => '__my__key__',
     'secret' => '__secret__key__'
));

$destination = 'downloaded_bucket';
$source_bucket = '__my__bucket__name';
$key_prefix = '';
$options = array('debug'=>true);

$client -> downloadBucket($destination,$source_bucket,$key_prefix,$options);
?>

现在从浏览器执行此php时,出现以下错误.

Now on executing this php from my browser, I get the following error.

Notice: Use of undefined constant STDOUT - assumed 'STDOUT' in __my__path\Aws\S3\Sync\AbstractSyncBuilder.php on line 294
STDOUT
Warning: fwrite() expects parameter 1 to be resource, string given in __my__path\Aws\S3\Sync\DownloadSyncBuilder.php on line 124
STDOUT
Warning: fwrite() expects parameter 1 to be resource, string given in __my__path\Aws\S3\Sync\DownloadSyncBuilder.php on line 124
STDOUT
Warning: fwrite() expects parameter 1 to be resource, string given in __my__path\Aws\S3\Sync\DownloadSyncBuilder.php on line 124

由于第一个通告出现了最后3条警告,因为传递了字符串'STDOUT'而不是资源.

The final 3 warnings occur because of the first Notice, because instead of resource, the string 'STDOUT' is passed.

首先发出通知的原因是什么? 此通知的代码段为

What is the reason for the first notice? The code segment for this notice is

if ($this->debug) {
            $this->addDebugListener($sync, is_bool($this->debug) ? STDOUT : $this->debug);
        }

,它是SDK的一部分. 而fwrite警告代码的罪魁祸首是addDebugListener函数

which is part of the SDK. And the culprit for the fwrite warning code is the addDebugListener function

protected function addDebugListener(AbstractSync $sync, $resource)
    {
       //blah blah
       fwrite($resource, "Downloading {$from} -> {$to}\n");
       //blah blah
    }

我的PHP版本是5.4.16

My PHP version is 5.4.16

推荐答案

在这种情况下,问题是未定义常量STDOUT.当使用命令行时,它是一个常数,因此,要在其他设置中使用它们,您可以执行以下操作:

The problem, in this case, is that the constant STDOUT is not defined. It is a constant available when using the command line, so in order to use them in other settings you can do this:

if(!defined('STDIN'))  define('STDIN',  fopen('php://stdin',  'rb'));
if(!defined('STDOUT')) define('STDOUT', fopen('php://stdout', 'wb'));
if(!defined('STDERR')) define('STDERR', fopen('php://stderr', 'wb'));

这将检查是否已定义常数,如果没有定义,请根据期望它们的工作方式对其进行定义.

This will check whether or not the constant has been defined, and if not, define them according to how they are expected to work.

有关常量的更多信息,可以在此处找到PHP文档.

More information about the constants can be found here in the PHP docs.

这篇关于注意:使用未定义的常量STDOUT-假定为"STDOUT"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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