Page 1 of 1
Passed by Value or Reference
Posted: Tue Aug 28, 2007 9:25 pm
by asif_phpdn
For PHP 5 objects are passed by reference and for PHP 4 that is passed by Value. Is it correct?
Posted: Tue Aug 28, 2007 11:40 pm
by Christopher
Yes, although PHP5 objects are actually a handle not a reference. See docs for the difference.
Posted: Thu Aug 30, 2007 8:38 pm
by asif_phpdn
Actually there is nothing passed by reference. Everything is just passed by value. Isn't it?
Posted: Thu Aug 30, 2007 9:31 pm
by Christopher
Pass by reference looks like this:
In PHP4 objects are like other variables so when they are passed normally a copy of the object is made. In PHP5 an object variable contains a handle to the actual object. So when you pass an object variable you create a copy of the variable, but when you use it both the original and copy contain a handle to the same object.
Posted: Fri Aug 31, 2007 5:36 am
by volka
asif_phpdn wrote:Actually there is nothing passed by reference. Everything is just passed by value. Isn't it?
But in php5 the object handle is passed (by value) instead of a copy of the object. So you will actually access the same object in your function.