2 ms·
>The very basic you need to know is: if a function argument is defined as (*foo), you are changing the item you pass to the function (like in Javascript or Java
by sergiotapia 14y ago
>The very basic you need to know is: if a function argument is defined as (*foo), you are changing the item you pass to the function (like in Javascript or Java), whereas if it's defined as (foo), you're changing a copy of it and the original item remains unaffected.
=============================
So it's like PHP where I need to pass in `function modify(&$foo) {` to modify a variable passed by reference.
- coldtea 14y agoYes, not sure for the whole PHP semantics on this, but it's a little like that.
- dnm 14y agoIt's also a performance boost when you're passing something non-trivial, to pass just the pointer, rather than have Go make a copy of whatever you're passing by value.
- chrisguitarguy 14y ago> So it's like PHP where I need to pass in `function modify(&$foo) {` to modify a variable passed by reference. If you're thinking in terms of PHP's primitive types, then yes: that's probably the best equivalent. PHP has the whole objects always being "passed by reference" [0] thing going on too. 0. http://php.net/manual/en/language.oop5.references.php http://php.net/manual/en/language.oop5.references.php