You are here: Is it worth it to return a resource by reference? « PHP Programming Language « IT news, forums, messages
Is it worth it to return a resource by reference?

Posted by Ney Andrι de Mello Zunino on 09/27/06 03:37

Hi.

I would like to know whether returning and passing around a resource
(e.g. like those returned by mysql_query) by reference is worth it or
nothing more than overkill. The reason I ask is because I don't know of
what a resource is actually made and I fear it might be so simple (e.g.
a mere number or pointer identifying a potentially big object) that
passing it by reference could even increase the overhead. What's the truth?

The situation I have is a function which queries and returns a given
range of objects (blog posts in this case) and another one which later
receives the result set and works through it to output the contents.
Something like the following sample code (using references):

// ----- BEGINNING OF SAMPLE CODE -----

function& getPosts(...)
{
return mysql_query(...);
}

function showPosts(&$postsResultSet)
{
while ($post = mysql_fetch_object($postsResultSet))
{
...
}
}

// driver code:
$results =& getPosts(...);
....
showPosts($results);

// ----- END OF SAMPLE CODE -----

Any comments will be appreciated.

Thank you,

--
Ney AndrΓ© de Mello Zunino

 

Navigation:

[Reply to this message]


УдалСнная Ρ€Π°Π±ΠΎΡ‚Π° для программистов  •  Как Π·Π°Ρ€Π°Π±ΠΎΡ‚Π°Ρ‚ΡŒ Π½Π° Google AdSense  •  England, UK  •  ΡΡ‚Π°Ρ‚ΡŒΠΈ Π½Π° английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Π‘Π°ΠΉΡ‚ ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ Π² Π‘Ρ‚ΡƒΠ΄ΠΈΠΈ Π’Π°Π»Π΅Π½Ρ‚ΠΈΠ½Π° ΠŸΠ΅Ρ‚Ρ€ΡƒΡ‡Π΅ΠΊΠ°
ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ΠΈΠ΅ ΠΈ ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΊΠ° Π²Π΅Π±-сайтов, Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠ° ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠ½ΠΎΠ³ΠΎ обСспСчСния, поисковая оптимизация