Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
call by value vs call by reference
Old 05-05-2005, 04:32 PM call by value vs call by reference
Recrehal's Avatar
Experienced Talker

Posts: 39
Location: Aachen, Germany
Trades: 0
For those who have no clue what both are:
call by value is the default way to handle parameters in a function. To handle them the copy operator is used so modifying the parameter won't change the original variable passed to the function.

function by_value($a, $b){}

call by reference alters the way parameters are handled. A reference is an alias for the passed variable so changing it will affect the original variable instead of a local copy. Instead of copying a whole lot of data, e.g. objects, call by reference safes a lot of storage due to not copying or, in other words, doubling the merory needed to store the object.

function by_reference(&$a, &$b){}

This beeing said, I'd like to discuss about an advice of Zend Studio 4:
Quote:
Contrary to popular belief, this [call by reference] actually reduces performance in most cases [...]
I'm using C++ a lot and this statement almost caused a heartattack O_o
The variables I pass are mainly large strings with more than 100 words and large arrays containing information about these large strings. Since PHP is significantly different from C++ I'm interested in the way PHP tries to speed up performance, though I have major doubts that this statement is actually true. The reason for my doubts is the fact that in most cases (in fact anything but small numbers) a pointer to the adress would consume less memory than safing the data. Theoretically everything below 256 bit would qualify for call by value and anything above those 256 bit for a call by reference. The question is, if PHP handles call by value faster than call by referene as than the performance would be better even with larger data (until what size, though?).

So if anyone can clear things up, feel welcome to join the discussion. As a focus I'd like to discuss the behavior of call by value vs call by reference on three major groups:
numbers and strings below 256 bit (I'm assuming a 32 bit adress machine),
strings containing significantly more than 256 Bit (50++ words), multidimensional arrays with a mixture of relativly small numbers and strings,
and objects in PHP 5

Last edited by Recrehal; 05-05-2005 at 04:42 PM..
Recrehal is offline
Reply With Quote
View Public Profile Visit Recrehal's homepage!
 
 
Register now for full access!
Reply     « Reply to call by value vs call by reference
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.08174 seconds with 12 queries