0

This line:

$source_file = $s3->inputResource(fopen($source, 'rb'), filesize($source));

produces the error: PHP Strict Standards: Only variables should be passed by reference

I can suppress the error but would like to know if there is a fix. Thanks

Rizier123
  • 58,877
  • 16
  • 101
  • 156
BDIll
  • 3
  • 1
  • 2
    Have you done any research? [This](http://stackoverflow.com/questions/29230584/php-strict-standards-only-variables-should-be-passed-by-reference) and [this](http://stackoverflow.com/questions/25727741/php-strict-standards-only-variables-should-be-passed-by-reference) questions have the same name as yours. Why don't they solve your problem? As you have a clear error message, have you tried Google? – ZygD Apr 24 '15 at 15:45

1 Answers1

0

I believe your issue is because you're trying to pass the result of a function call that isn't returning a reference to a function whose parameter is defined to accept a reference.

This is what is stated in the manual:

The following things can be passed by reference:

  • Variables, i.e. foo($a)
  • New statements, i.e. foo(new foobar())
  • References returned from functions

fopen isn't returning a reference, so trying to call it inline while passing a parameter to a function accepting a reference isn't valid. Try this:

$fp = fopen($source, 'rb');
$source_file = $s3->inputResource($fp, filesize($source));

The manual describes this example as valid (because bar() returns a reference):

<?php
function foo(&$var)
{
    $var++;
}
function &bar()
{
    $a = 5;
    return $a;
}
foo(bar());
?>

And this example is invalid (which is what I think is happening):

<?php
function foo(&$var)
{
    $var++;
}
function bar() // Note the missing &
{
    $a = 5;
    return $a;
}
foo(bar()); // Produces fatal error since PHP 5.0.5
Community
  • 1
  • 1
Jeff Lambert
  • 24,395
  • 4
  • 69
  • 96