& (and) in inner-function, do the top level functions inherit it?
func开发者_如何学Pythontion clean($data, &$user) { //<- do I need to have the and here as well?
$dataB = coolStuff($user);
return dataA * $dataB;
}
function coolStuff(&$user){
return $user++;
}
Do I need to have the & in front of my function carried onto the top level function as well?
Yes, it has to be in any function where you want a reference to the object rather than a copy. Example:
function clean($data, &$user) {
$dataB = coolStuff($user);
return $data * $dataB;
}
function coolStuff(&$user) {
return $user++;
}
You have to, if you want to have &user to be changed outside the clean() function too.
精彩评论