(PHP) What is the difference between a static variable and a "pass by reference" variable?
-
I understand that a static variable will maintain its' current value within its' scope (function), and that when accessed again under whatever circumstance will have maintained its' last initialized value. I understand that a "pass by reference" value will actually permanently change the initial value of the variable that was passed by reference, whatever the scope may be. So, are these not the same in functionality?
-
Answer:
A reference and static variables are very different. It is true that if a variable is not declared static within a function, it is released when control returns from the funtion. A static variable will retain its value every time that function is called. So if you were to change a static variable's value to 2 within a function, during the next function call, the variable would have a value of two. But a static variable's scope is local to that function. It cannot be accessed outside of that function. A reference variable on the other hand, is very different. It is a variable that "references" another variable by use of memory addresses. It is essentially another name for that variable that can be passed to a function to change the variable it is referencing. So with reference variables you have more freedom in a sense. You can use that reference variable for any function you declare and modify the variable it is referencing
Ian at Yahoo! Answers Visit the source
Related Q & A:
- What is the difference between a static method and class method in Python?Best solution by pythoncentral.io
- What is the difference between a bar, a tavern, a pub, and a saloon?Best solution by Yahoo! Answers
- What's the difference between a private franchise and a public franchise?Best solution by answers.yahoo.com
- What's the difference between a static data member and a regular data member?Best solution by eHow old
- What is the difference between a sociological concept and a variable?Best solution by wiki.answers.com
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.