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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T17:08:03+00:00 2026-05-10T17:08:03+00:00

Is it a problem if you use the global keyword on variables you don’t

  • 0

Is it a problem if you use the global keyword on variables you don’t end up using? Compare:

function foo() {     global $fu;     global $bah;     if (something()) {         $fu->doSomething();     } else {         $bah->doSomething();     } }  function bar() {     if (something()) {         global $fu;         $fu->doSomething();     } else {         global $bah;         $bah->doSomething();     } } 

I’m quite aware that using the second method makes maintaining this code much harder, and that it’s generally preferred to put all your globals at the start of functions, so: Ignoring the difference in maintainability and code-styling of the two functions, is there a difference between these two in terms of overhead?

  • 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. 2026-05-10T17:08:03+00:00Added an answer on May 10, 2026 at 5:08 pm

    If there is, it won’t be (humanly) measurable, unless you are literally calling this function millions of times. And even if it was a recursive function with that property, I still wouldn’t use your second method for the maintainability aspects you already brought up.

    Edit: For arguments sake, I actually went and benchmarked this, and bar() ended up slower by 0.1s over one million calls. Which means performance wise, you still have a reason to use the cleaner version.

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

Sidebar

Related Questions

Weird problem here, I'm trying to use a global function to update my settings
which is the cleanest way to use something like a global variable? Normally, using
I am using this plugin. However it seems to use global variables $.blockUI(); $.unblockUI();
I have a problem. When I use global variables in my php code, my
I am using wordpress and use custom permalink structure: /%category%/%postname%/ My problem is that
I tried using Global Hooks using SetWindowsHookEx to get all the the keystrokes. Problem
I want to use a global Style in WP7, something like: <Style TargetType=Button> //some
I'm using CodeIgniter and I came across an interesting problem. I need to use
The Problem I use a tool at work that lets me do queries and
I have found a problem with use JQuery timeout, i have a page with

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.