分类:
2008-03-01 09:33:36
PHP.ini在PHP的一些版本中默认allow_call_time_pass_reference为Off 即不允许运行时传递引用变量..
[code]
function func($a) ';
{
$a = 'test';
}
$xx = '';
func(&$xx); // 默认情况下会有出错提示...
你要么改函数的声明成:
function func(&$a)
{
$a = 'test';
}
$xx = '';
func($xx);
[/code]
或改php.ini中allow_call_time_pass_reference为On
笔者的PHP5的php.ini的allow_call_time_pass_reference默认为on,特意改成off。
PS: 在运行时传递引用不是一个好习惯..
以下是本人的一个练习:
[code]
function func1(&$a)
{
echo '$xx初值为:'.$a.'
';
$a="中国";
}
$xx = '测试';
func1($xx);
echo '最后$xx的值为:'.$xx.'
?>
function func2($a)
{
echo '$xx初值为:'.$a.'
';
$a="中国";
}
$xx = '测试';
func2($xx);
echo '最后$xx的值为:'.$xx;
?>
[/code]