Notice: Use of undefined constant STDOUT - assumed 'STDOUT'

我只是一个虾纸丫 提交于 2019-12-13 12:23:43

问题


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

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);
?>

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

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

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
    }

My PHP version is 5.4.16


回答1:


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'));



回答2:


You should add, in your own code, something like :

define("STDOUT", fopen('log.txt', 'w'));

Information about files transfered will be logged into the file 'log.txt'.



来源:https://stackoverflow.com/questions/17769041/notice-use-of-undefined-constant-stdout-assumed-stdout

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!