Forum Moderators: coopster

Message Too Old, No Replies

Difference between $cnn and &$cnn

         

asantos

8:42 pm on Nov 25, 2006 (gmt 0)

10+ Year Member



Hi, i was wondering what is the exact performance difference between this two lines of code:

$rs = &$cnn->Execute($sql);

$rs = $cnn->Execute($sql);

Thanks

whoisgregg

9:10 pm on Nov 25, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The best way to determine the difference would be to do some benchmarking on your own code. :)

That said, the PHP manual section on references [php.net] might be handy -- perhaps especially this page [php.net] that says:

Do not use return-by-reference to increase performance, the engine is smart enough to optimize this on its own. Only return references when you have a valid technical reason to do it!

Of course, I don't really grok references so I'm not sure if that does apply in this case but it seemed the only discussion of the impact on references to performance.

mcibor

8:07 pm on Nov 26, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



As I know, the problem may appear when you perform sth like this:

$rs1 = &$cnn->Execute("SELECT id FROM table");
$rs2 = &$cnn->Execute("SELECT name FROM table");

echo $rs1 -> data();// somehow show the data from $rs1
echo $rs2 -> data();//

I think both will output names - you would loose what you wanted to have in rs1.
However I may be wrong. It requires testing.

Michal