General Question

Breefield's avatar

If I store $_GET in $get will I double the memory that $_GET takes up?

Asked by Breefield (2728points) July 23rd, 2008

Just because I like to have things my way :)

Observing members: 0 Composing members: 0

4 Answers

richardhenry's avatar

Well yes, since you’re duplicating the same data into two separate variables.

That said, unless you’re running on a shoe string, it really won’t be that much of a performance hit unless you’re accepting a whole plethora of input.

I suppose you could unset $_GET, but it seems silly to me. Just carry on as you are.

Breefield's avatar

Yeah, I figured. I wonder if it’s possible to make pointer variables…I’m trying to save what, 2 kb? :D

Vincentt's avatar

Nope, it doesn’t. When you copy a variable into another variable, behind the scenes PHP will only make that variable refer to the same data, so it only uses a little more. When you start manipulating the data (so $_GET and $get diverge), PHP will create a copy.

So if you just like to do things your way without manipulating $get, you can do so. If you want to be absolutely sure, you can do

$get =& $_GET; // Hmm… Or perhaps it was &=

which means that $get references $_GET, and thus that they refer to the exact same data. So when you manipulate one, the other is also altered.

Yet, I’d recommend you to follow standard PHP practice (i.e. use $_GET instead of $get) because you might get in trouble if you ever have to work with other developers.

Breefield's avatar

That’s incredible, it’s like smart pointing (smart typing).

Answer this question




to answer.

This question is in the General Section. Responses must be helpful and on-topic.

Your answer will be saved while you login or join.

Have a question? Ask Fluther!

What do you know more about?
Knowledge Networking @ Fluther