<?php
function &test_function($index)
{
$test = array('deng', 'chao', 'hello');
if(isset($test[$index]))
{
return $test[$index];
}
else
{
//环境一
define('ERROR', "not $index");
return ERROR;
//环境二
return "not $index";
//环境三
$error = "not $index";
return $error;
}
}
echo test_function(5);
?>
错误:Notice: Only variable references should be returned by reference
环境:
函数返回的是一个引用时,以上代码会出现以下所描述问题。
环境一和环境二会产生如上错误。不致命
环境三无任何错误,正常完成。
结论:函数返回类型为引用是不能直接返回常量,
原因:主要原因是PHP5运行PHP4的代码。 摘自百度空间