If you pass a variable to a function (for example, $ var), is it assumed that this is a copy of the reference to the actual variable (such that setting it to null does not affect other copies)?
Depends on function. And also, as you call it. Have a look at this example: http://www.ideone.com/LueFc
Or does he get a link to what is a new copy of the actual variable (such that setting it to zero destroys only its copy)?
Depends on function again
If the latter, does it copy objects and arrays into memory? This seems like a good way to lose memory and CPU time if that is the case.
He is going to save memory in order to use the link, of course. In php> 4, it always uses a reference for objects, unless you specify otherwise.
What is a deal with local reach? Have I noticed correctly that I can declare an array in one function and then use this array in other functions called inside this function WITHOUT passing them to them as a parameter?
No, you canโt.
Similarly, declaring in an array in a function called inside a function allows it to be available in the caller?
No, it is not.
If not, does the inscription on the call stack work or something like every bloody thing I understood about programming, do I need it?
If you want to use a variable from outside the function, you must write global $outsidevar before using it
profitphp
source share