By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,837 Members | 1,766 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,837 IT Pros & Developers. It's quick & easy.

Pass by reference via 'return' a variable...

P: n/a
Hi all,

Quick question: If I have a function which populates a large array (ie.
reading rowsets), is it better to pass in a reference to a variable to
accept the data, or should I just create, populate and return the array
from the function?

Thanks in advance!

Oct 10 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Passing reference is preferred because passing an array back is seen as
more of a 'hack'
TeejB wrote:
Hi all,

Quick question: If I have a function which populates a large array (ie.
reading rowsets), is it better to pass in a reference to a variable to
accept the data, or should I just create, populate and return the array
from the function?

Thanks in advance!
Oct 11 '06 #2

P: n/a
I guess the question is: will PHP optimize this for me so that the
entire contents aren't copied out of the function, or do I have to pass
in a reference?
Benjamin wrote:
Passing reference is preferred because passing an array back is seen as
more of a 'hack'
TeejB wrote:
Hi all,

Quick question: If I have a function which populates a large array (ie.
reading rowsets), is it better to pass in a reference to a variable to
accept the data, or should I just create, populate and return the array
from the function?

Thanks in advance!
Oct 12 '06 #3

P: n/a
You have to pass a reference.
TeejB wrote:
I guess the question is: will PHP optimize this for me so that the
entire contents aren't copied out of the function, or do I have to pass
in a reference?
Benjamin wrote:
Passing reference is preferred because passing an array back is seen as
more of a 'hack'
TeejB wrote:
Hi all,
>
Quick question: If I have a function which populates a large array (ie.
reading rowsets), is it better to pass in a reference to a variable to
accept the data, or should I just create, populate and return the array
from the function?
>
Thanks in advance!
Oct 13 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.