Passed by Value or Reference
Moderator: General Moderators
-
asif_phpdn
- Forum Commoner
- Posts: 28
- Joined: Sun Aug 26, 2007 8:50 pm
Passed by Value or Reference
For PHP 5 objects are passed by reference and for PHP 4 that is passed by Value. Is it correct?
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
-
asif_phpdn
- Forum Commoner
- Posts: 28
- Joined: Sun Aug 26, 2007 8:50 pm
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
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.
Code: Select all
function foo(&$bar) {(#10850)