考虑:
public function & get($name, $default = null)
为什么要使用 &
符号?
考虑:
public function & get($name, $default = null)
为什么要使用 &
符号?
<?php
$foo = 'foo';
function & get_foo_ref ()
{
global $foo;
return $foo;
}
// Get the reference to variable $foo stored into $bar
$bar = & get_foo_ref();
$bar = 'bar';
echo $foo; // Outputs 'bar', since $bar references to $foo.
?>
&
,那么$foo
变量仍将包含'foo',因为只有值而不是引用是从函数返回的。这意味着它返回结果的引用,而不是它的副本。