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 6008717
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:51:51+00:00 2026-05-23T01:51:51+00:00

This is not a theoretical or general question about when to use pass by

  • 0

This is not a theoretical or general question about when to use “pass by reference” vs “pass by value”. Several questions of that type here, and NONE of them answer my very specific question:

In PHP, when passing a database connection resource ID to a function (just a simple procedural function, not any class or anything complicated) does it matter if I pass by reference or by value?

The connection itself does absolutely nothing. It is never changed. So both reference and value work fine.

My question I suppose is to figure out WHY I would pass it by reference. I have old inherited code, and the comments in the code suggest that passing by reference saves memory and speeds up performance. I wonder if this is true?

Btw I am using Postgresql connections, not MySQL.

Thanks!

  • 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-05-23T01:51:52+00:00Added an answer on May 23, 2026 at 1:51 am

    A database connection is a “resource”. It is usually just a pointer, so it doesn’t matter whether you pass it by value or by reference. Resources behave like objects in this sense.

    Passing by reference used to have a significant effect on memory usage in the past. That’s why old code contains so many & operators. But this is no longer necessary. PHP 5 uses copy-on-write semantics for variables, so it doesn’t cost any more memory to pass things by value in most circumstances. Especially if it’s just a pointer like a resource… but this also applies to other types of variables such as string and arrays. (Try passing a 1MB string by value. Memory consumption will NOT go up by 1MB.)

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

Sidebar

Related Questions

This is mostly a theoretical question I'm just very curious about. (I'm not trying
My question is not exactly the same as this one (it's not theoretical, there
Sorry for this not being a real question, but Sometime back i remember seeing
$(#dvMyDIV).bind(resize, function(){ alert(Resized); }); or $(#dvMyDIV).resize(function(){ alert(Resized); }); The questions Why is this not
This is not exactly a programming question, but it's highly related. We are writing
This may not be the correct way to use controllers, but I did notice
This question is theoretical as well as practical. Any results indicating useful resources on
It seems to be the general opinion that tables should not be used for
Under what circumstances would this or would this not be safe? I have a
Ok, so, my visual studio is broken. I say this NOT prematurely, as it

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.