开发者

& (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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜