Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8440263
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T08:14:38+00:00 2026-06-10T08:14:38+00:00

When passing arguments to functions, the convention is to pass by value if the

  • 0

When passing arguments to functions, the convention is to pass by value if the function is not supposed to change the value of that argument. We pass &byref only when the function is going to modify that variable.

On the other hand, we do know that when passing by reference, PHP works with a pointer, rather than duplicating a copy of the variable as in the case with passing by value.

This brings up a question in my mind, shouldn’t it we pass certain variables to our functions by reference from time to time for speed and efficiency purposes – even though we need them not modified.

Without getting crazy with the idea amd totally abuse it, I’d like to put a frame of reference as to which variables or what kind of variables I’m talking about here.

They are mainly $dbh ( database handles ) and very large variables. to tell you the truth, just the $dbh’s! really.

In your opinion, do you think this is a good practice or do you find it as one that should never be practiced.

Let’s bring this matter down to a code snippet and comment off of that.

//assume $dbh is the database_handle for a mysql connection

for ($userID = 1; $userID <= 1000; $userID++) {

        display_name ($dbh,"users",$userID)// outputs the name of the passed userid 
}

here, should the display_name function take the $dbh by ref or by value?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T08:14:39+00:00Added an answer on June 10, 2026 at 8:14 am

    PHP uses copy-on-write, which esentially means as long as the variable is not modified, passing it by value has the same effect as passing it by reference. That is to say, there will be no performance gain by using references in the scenario you describe (in fact, some report references can be slower)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Total noobie question here. I'm just learning Java, and studying passing arguments to functions.
How can one call a ColdFusion function, passing in attribute values as arguments, inside
I have problem with passing an argument to my simple function in jQuery: When
Can we say passing a function pointer as an argument to a function is
error: passing 'const QByteArray' as 'this' argument of 'QByteArray& QByteArray::append(const QByteArray&)' discards qualifiers [-fpermissive]
With pure Python functions you can pass arguments either by order (e.g. foo(1, 2,
I would like to understand the logic R uses when passing arguments to functions,
Is it somehow possible? I want that to enable compile-time passing of arguments. Suppose
How can you invoke a function in JavaScript, while passing in arguments, using a
I'm writing a function in C that takes a variable number of arguments. size_t

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.