Skip to main content

Questions tagged [global]

Refers to a space where variables and other items may be accessed from any scope.

global
92 votes
6 answers
43k views

Are global variables in PHP considered bad practice? If so, why? [duplicate]

function foo () { global $var; // rest of code } In my small PHP projects I usually go the procedural way. I generally have a variable that contains the system configuration, and when I nead ...
KRTac's user avatar
  • 2,837
339 votes
10 answers
477k views

Using global variables between files?

I'm bit confused about how the global variables work. I have a large project, with around 50 files, and I need to define global variables for all those files. What I did was define them in my ...
user avatar
491 votes
11 answers
182k views

What does "nonlocal" do in Python 3?

What does nonlocal do in Python 3.x? To close debugging questions where OP needs nonlocal and doesn't realize it, please use Is it possible to modify variable in python that is in outer, but not ...
ooboo's user avatar
  • 16.7k
46 votes
9 answers
49k views

Why are global variables considered bad practice?

I keep seeing warnings not to use global variables in JavaScript, but it seems that the only reason people say that is because the clogs up the global namespace. I can imagine this being easily fixed ...
user1318416's user avatar
1283 votes
14 answers
580k views

Global Git ignore

I want to set up Git to globally ignore certain files. I have added a .gitignore file to my home directory (/Users/me/) and I have added the following line to it: *.tmproj But it is not ignoring ...
Mild Fuzz's user avatar
  • 30.3k
193 votes
3 answers
134k views

What happens to global and static variables in a shared library when it is dynamically linked?

I'm trying to understand what happens when modules with globals and static variables are dynamically linked to an application. By modules, I mean each project in a solution (I work a lot with visual ...
Raja's user avatar
  • 3,016
156 votes
9 answers
301k views

Global variables in Javascript across multiple files

A bunch of my JavaScript code is in an external file called helpers.js. Inside the HTML that calls this JavaScript code I find myself in need of knowing if a certain function from helpers.js has been ...
Goro's user avatar
  • 10.1k
130 votes
12 answers
193k views

How to make a cross-module variable?

The __debug__ variable is handy in part because it affects every module. If I want to create another variable that works the same way, how would I do it? The variable (let's be original and call it '...
Dan Homerick's user avatar
  • 4,208
37 votes
6 answers
186k views

Passing Variable through JavaScript from one html page to another page

I have two pages - "page 1" and "page 2". On page 1 there's an text-box with a value of e.g. 100 and a button at the end. By pressing the button I want javascript to save the value of the textbox in ...
Kronwied's user avatar
  • 391
205 votes
10 answers
521k views

How to declare a global variable in php?

I have code something like this: <? $a="localhost"; function body(){ global $a; echo $a; } function head(){ global $a; echo $a; } function ...
LIGHT's user avatar
  • 5,694
86 votes
11 answers
63k views

How to get the global object in JavaScript?

I want to check in a script if a certain other module is already loaded. if (ModuleName) { // extend this module } But if ModuleName doesn't exist, that throws. If I knew what the Global Object ...
coolaj86's user avatar
  • 75.9k
61 votes
4 answers
84k views

Why are global variables always initialized to '0', but not local variables? [duplicate]

Possible Duplicate: Why are global and static variables initialized to their default values? See the code, #include <stdio.h> int a; int main(void) { int i; printf("%d %d\n", a, i);...
yuvanesh's user avatar
  • 1,113
35 votes
4 answers
26k views

Assign multiple objects to .GlobalEnv from within a function

A post on here a day back has me wondering how to assign values to multiple objects in the global environment from within a function. This is my attempt using lapply (assign may be safer than <<...
Tyler Rinker's user avatar
12 votes
2 answers
710 views

'this' different between REPL and script

After reading through mozilla docs I found this: In the global execution context (outside of any function), this refers to the global object, whether in strict mode or not. After playing with ...
Maciej Goszczycki's user avatar
5 votes
2 answers
2k views

Android startCamera gives me null Intent and ... does it destroy my global variable?

I have the next problem: when I try to start my camera, I can take the picture, even save it on my sdcard, but when I'm going to get the path for showing it on my device I get errors. My global ...
Rafael Ruiz Muñoz's user avatar

15 30 50 per page
1
2 3 4 5
35