2011-03-25 58 views
1
function clean($data, &$user) { //<- do I need to have the and here as well? 
    $dataB = coolStuff($user); 
    return dataA * $dataB; 
} 



function coolStuff(&$user){ 
return $user++; 
} 

我是否需要將&放在頂層函數的函數前面?&(和)在內函數中,頂層函數是否繼承它?

+0

對不起,問題是錯誤地陳述,我已經更新它。 – Mohammad 2011-03-25 20:42:55

回答

1

是的,它必須在任何你想要引用對象而不是副本的函數中。例如:

function clean($data, &$user) { 
    $dataB = coolStuff($user); 
    return $data * $dataB; 
} 

function coolStuff(&$user) { 
    return $user++; 
} 
1

,如果你想擁有&用戶你要到乾淨的()函數外也發生了變化。