pass-by-reference

PHP Variables passed by value or by reference?

I had a Java developer new to PHP ask me this question the other day, so I thought I'd document the answer here. Question: are PHP variables passed by value or by reference?...

pass by reference or pass by value?

When learning a new programming language, one of the possible roadblocks you might encounter is the question whether the language is, by default, pass-by-value or pass-by-reference So here is my question to all of you, in your favorite language, how is it actually done? and what are the possible pitfalls? your favorite language can, of...

Is Java pass by reference?

I always thought Java was pass by reference, however I've seen a couple of blog posts (e.g. this blog) that claim it's not. I don't think I understand the distinction they're making. Could someone explain it please? ...

In PHP (>= 5.0), is passing by reference faster?

In PHP, function parameters can be passed by reference by prepending an ampersand to the parameter in the function declaration, like so: function foo(&$bar) { // ... } Now, I am aware that this is not designed to improve performance, but to allow functions to change variables that are normally out of their scope. Instead, PHP see...

Is it better in C++ to pass by value or pass by constant reference?

Is it better in C++ to pass by value or pass by constant reference? I am wondering which is better practice. I realize that pass by constant reference should provide for better performance in the program because you are not making a copy of the variable. ...

How do I access 'this' from within a C# extension method?

I've been working with Vector2's and XNA, and I've come to find that calling the Normalize() member fuction on a Zero Vector normalizes it to a vector of {NaN, NaN}. This is all well and good, but in my case I'd prefer it instead just leave them as Zero Vectors. Adding this code to my project enabled a cute extension method: using Ext...

C++ - passing references to boost::shared_ptr

If I have a function that needs to work with a shared_ptr, wouldn't it be more efficient to pass it a reference to it (so to avoid copying the shared_ptr object)? What are the possible bad side effects? I envision two possible cases: 1) inside the function a copy is made of the argument, like in ClassA::take_copy_of_sp(boost::shared_pt...

Java: How to pass byte[] by reference?

You can do it in .NET by using the keyword "ref". Is there any way to do so in Java? Thanks in advance! ...

Are there benefits of passing by pointer over passing by reference in C++?

Are there benefits of passing by pointer over passing by reference in C++? Lately, I have seen a number of examples that pass the a pointer instead of passing by reference. Are there benefits to doing this? Example: func(SPRITE *x); with a call of func(&mySprite); vs. func(SPRITE &x); with a call of func(mySprite); ...

How can I pass a reference to a function, with parameters?

I need to able to pass a reference to a function with a given set of parameters. Here is an example of passing a reference without parameters: var f = function () { //Some logic here... }; var fr = f; //Here I am passing a reference to function 'f', without parameters fr(); //the 'f' function is invoked, without parameters Now w...

What's the difference between a parameter passed by reference vs. passed by value?

I need help. what is difference between a parameter passed by reference, and a parameter passed by value? Could you give me some examples please? ...

references in visual basic .net

Hi, Somewhat unclear to me are references (pointers?) to classes in Visual Basic .Net. The question I am about to ask can be answered by a little bit of testing, but I was wondering if anybody could post a decent explanation (or links, too). If you create a class: Public Class ReferenceClass private myBooleanValue as Boolean = F...

ASP.NET 2.0: Specifying an instance of an object for an ObjectDataSource

I'm using an ObjectDataSource to bind data to a GridView; it works fine except that it always creates a new object to use as a data source. I can do all the setup just fine but I cannot use an instance of an existing object to specify as the "data source" for it. Is it possible to do this? If so, how? If it's not possible, why? ED...

Pass by Reference / Value in C++

Hi, I would like to clarify the differences between by value and by reference. I drew a picture So, for passing by value, a copy of an identical object is created with a different reference, and the local variable is assigned the new reference, so to point to the new copy How to understand the words: " If the function modifies tha...

Need to reference a variable using the value stored in a string vb6

I am looping through some code using a For loop. The iterative variable is "i". I have dimensioned the following variables prior to the For Loop. L1, L2, L3, L4 as strings. I want to reference these strings inside the For loop by somehow referring to "L" & char(i). So like a comparison of a value "Foo" <> "L" & Char(i), should result is ...

C++ Why is this passed-by-reference array generating a runtime error?

void pushSynonyms (string synline, char matrizSinonimos [1024][1024]){ stringstream synstream(synline); vector<int> synsAux; int num; while (synstream >> num) {synsAux.push_back(num);} int index=0; while (index<(synsAux.size()-1)){ ...

Giving to child access to parent's member by reference - is it OK?

C++ newbie question. Please, verify I'm doing it right. I have a global application class spawning it's little kids and I need to give the kids access to some of the application facilities. So I decided to pass them to children by reference. I tested the idea as show below. It seems to work fine. I just wanted to make sure I'm not doin...

Why should I use the keyword "final" on a method parameter in Java?

I can't understand where the final keyword is REALLY handy when it is used on method parameters. If we exclude the usage of anonymous classes, readability and intent declaration then it seems almost worthless to me. Enforcing that some data remains constant is not as strong as it seems. A) If the parameter is a primitive then it w...

Can someone explain to me what the reasoning behind passing by "value" and not by "reference" in Java is?

I'm fairly new to Java (been writing other stuff for many years) and unless I'm missing something (and I'm happy to be wrong here) the following is a fatal flaw... String foo = new String(); thisDoesntWork(foo); System.out.println(foo);//this prints nothing public static void thisDoesntWork(String foo){ foo = "howdy"; } Now, I'm w...

Passing values in Python

When you pass a collection like list, array to another function in python, does it make a copy of it, or is it just a pointer? ...