There is nothing to stop you from manipulating this variable. I don’t know anything that indicates that it will create a problem. There is nothing in the documentation that says you should avoid. But some weightings should be noted.
- PHP is not the best language to work with large volumes of data at once. Much less is the language to think about when expecting great optimization of resource use. If you really need this, choose the right tool.
- With
$_GET
you cannot manipulate millions of data. Never even thousands will come if the protocol is respected.
- If you will receive millions of fields in a single request you are doing something very wrong, there are so many other problems that can occur, so much to worry that this problem comes to be almost irrelevant.
- PHP does not keep data in memory that is no longer referenced. At least it says it does not. So I don’t know if I’d have this duplicate that you expect.
- You need to see if you really need to duplicate. I understand that you want to write in this array. But almost always what people want is just to read its content and use it somewhere. There’s no problem in this. Nothing. I notice that some programmers think it is necessary to play a field coming through
$_POST
in a local variable and then use the variable. This is really a waste probably caused by people’s insistence on following cake recipe instead of learning to develop software.
- Other than that, it’s completely unnecessary optimization.
- If you still insist on this, do a test stress and come to some conclusion for your real case. No one can give you better information than this.
The exception would be if using threads, which I doubt is the case. By the nature of PHP programs they rarely benefit a program. Again, if someone thinks they need to thread to get better performance she will probably choose another language.
The memory or processing supposedly wasted is tiny for you to worry about. If I remember correctly, what you should avoid is using those "famous" ternaries when the variable they tested contains enough information. Other than that, focus on avoiding other gluten traps throughout the Application and you will be covered.
– Bruno Augusto
Okay, in another scenario, where there are "millions" of bank submissions, one could directly manipulate the superglobal in order to save memory?
– Ricardo