Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.