$s3 - PHP 严格标准:只有变量应该通过引用传递
$s3 - PHP Strict Standards: Only variables should be passed by reference
这一行:
$source_file = $s3->inputResource(fopen($source, 'rb'), filesize($source));
产生错误:
PHP 严格的标准:只有变量应该通过引用传递
我可以抑制错误,但想知道是否有修复方法。谢谢
我认为您的问题是因为您试图传递函数调用的结果,该函数调用未返回对参数定义为接受引用的函数的引用。
这就是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
未返回 reference,因此在将参数传递给接受引用的函数时尝试内联调用它是无效的。试试这个:
$fp = fopen($source, 'rb');
$source_file = $s3->inputResource($fp, filesize($source));
手册将此示例描述为有效(因为 bar()
returns 有参考):
<?php
function foo(&$var)
{
$var++;
}
function &bar()
{
$a = 5;
return $a;
}
foo(bar());
?>
而且这个例子是无效的(这是我认为正在发生的事情):
<?php
function foo(&$var)
{
$var++;
}
function bar() // Note the missing &
{
$a = 5;
return $a;
}
foo(bar()); // Produces fatal error since PHP 5.0.5
这一行:
$source_file = $s3->inputResource(fopen($source, 'rb'), filesize($source));
产生错误: PHP 严格的标准:只有变量应该通过引用传递
我可以抑制错误,但想知道是否有修复方法。谢谢
我认为您的问题是因为您试图传递函数调用的结果,该函数调用未返回对参数定义为接受引用的函数的引用。
这就是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
未返回 reference,因此在将参数传递给接受引用的函数时尝试内联调用它是无效的。试试这个:
$fp = fopen($source, 'rb');
$source_file = $s3->inputResource($fp, filesize($source));
手册将此示例描述为有效(因为 bar()
returns 有参考):
<?php
function foo(&$var)
{
$var++;
}
function &bar()
{
$a = 5;
return $a;
}
foo(bar());
?>
而且这个例子是无效的(这是我认为正在发生的事情):
<?php
function foo(&$var)
{
$var++;
}
function bar() // Note the missing &
{
$a = 5;
return $a;
}
foo(bar()); // Produces fatal error since PHP 5.0.5