Jump to content

PHP and References


SchweppesAle

Recommended Posts

PHP automatically passes all objects through reference, and that's about 90% of cases you need it.

Other 10% is for whenever you want a function to return a result of its actions through argument (like preg_match_all or shuffle).

 

As to whether one is faster than other or not... that's hardly relevant, because you should choose method basing on what you want to achieve and not on performance.

Link to comment
https://forums.phpfreaks.com/topic/186943-php-and-references/#findComment-987184
Share on other sites

PHP automatically passes all objects through reference, and that's about 90% of cases you need it.

Other 10% is for whenever you want a function to return a result of its actions through argument (like preg_match_all or shuffle).

 

As to whether one is faster than other or not... that's hardly relevant, because you should choose method basing on what you want to achieve and not on performance.

 

If PHP automatically passes them through reference then why use the & character? 

 

Also, if I wanted to delete a series of database entries,  I could concatinate one huge query string which does it all in one shot or I can run 200 queries for each database entry.  How is performance not an issue?

Link to comment
https://forums.phpfreaks.com/topic/186943-php-and-references/#findComment-987210
Share on other sites

PHP automatically passes objects by reference, not all variables. You use the & character for variables that are not objects, and the & does a little more than just passing by reference. (check out the manual for more information)

 

As far as speed, yes speed is important when you are programming, but the pass by value vs. by reference decision is made when you need the functionality of one over the other. When you need too pass by reference, you do, and likewise, if you need to pass by value, you do. Also the example you cited had nothing to do with passing by reference or value, so I don't see how its relevant

Link to comment
https://forums.phpfreaks.com/topic/186943-php-and-references/#findComment-987211
Share on other sites

Also, if I wanted to delete a series of database entries,  I could concatinate one huge query string which does it all in one shot or I can run 200 queries for each database entry.  How is performance not an issue?

 

That's hardly the same situation. You can create such a query in a variety of ways, using variable references or not.

Link to comment
https://forums.phpfreaks.com/topic/186943-php-and-references/#findComment-987218
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.