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

  • Home
  • SEARCH
  • 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 594579
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T15:58:07+00:00 2026-05-13T15:58:07+00:00

sorry i’m a beginner and i can’t determine how good a question this is,

  • 0

sorry i’m a beginner and i can’t determine how good a question this is, maybe it sounds utterly obvious to some of you.

if our use of these two below is the same which is better?

function doSomething ($var1,$var2,..){
    ...
}

OR

function doSomething (){
    global $var1,$var2,..;
    ...
}

by our use I mean that I know that in the second scenario we can also alter the global variables’ value. but what if we don’t need to do that, which is the better way of writing this function? does passing variables take less memory than announcing global’s in a function?

  • 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-13T15:58:08+00:00Added an answer on May 13, 2026 at 3:58 pm

    The memory usage is a paltry concern. It’s much more important that the code be easy to follow and not have… unpredicted… results. Adding global variables is a VERY BAD IDEA from this standpoint, IMO.

    If you’re concerned about memory usage, the thing to do is

    function doSomething (&$var1, &$var2,..) {
       ...
    }
    

    This will pass the variables by reference and not create new copies of them in memory. If you modify them during the execution of the function, those modifications will be reflected when execution returns to the caller.

    However, please note that it’s very unusual for even this to be necessary for memory reasons. The usual reason to use by-reference is for the reason I listed above (modifying them for the caller). The way to go is almost always the simple

    function doSomething ($var1, $var2) {
        ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sorry if this sounds like a really stupid question, but I need to make
Sorry for this not being a real question, but Sometime back i remember seeing
Sorry for the second newbie question, I'm a developer not a sysadmin so this
Sorry if this seems like a silly question - I am an amateur when
Sorry if this is a newbie question. I have searched but found nothing... Using
Sorry, lots of code coming up.. I saw another question like this that used
Sorry for the basic question - I'm a .NET developer and don't have much
Sorry, I'm new to SVN and I looked around a little for this. How
Sorry if the title is poorly descriptive, but I can't do better right now
Sorry for the long question title. I guess I'm on to a loser on

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.