Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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

like image 929
SatheeshJM Avatar asked Jul 21 '13 04:07

SatheeshJM


1 Answers

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.

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

like image 154
Ronny Sherer Avatar answered Oct 11 '22 00:10

Ronny Sherer