Refers to a space where variables and other items may be accessed from any scope.
Questions tagged [global]
4669 questions
16
votes
5 answers
What is the difference between session variables and global variables in php?
What is the difference between session variables and global variables in PHP?

Srividhya
- 389
- 1
- 4
- 15
16
votes
3 answers
How can I catch exceptions thrown from constructor of a global instance of a class?
I know that having global variables is not appreciated. But in the book, The C++ programming language, by Bjarne Stroustrup, Author says that " The only way to gain control in case of throw from an initializer of a non local static object is…

sajas
- 1,599
- 1
- 17
- 39
16
votes
2 answers
Javascript Regexp not returning global results
It's my understanding that all three of these lines below should return an ARRAY with 2 results in it. Yet RegExp will only return 1 result no matter how many times the regex repeats in the string.
Can some one explain why? And perhaps suggest how I…

StefanHayden
- 3,569
- 1
- 31
- 38
15
votes
5 answers
In C++, how can I make typedefs visible to every file in my project?
I have a typedef
typedef unsigned int my_type;
used in a file. I would like to make it visible across all my files, without
putting it in a header file included by everything. I don't want to go the header file
route because as it stands this will…

user231536
- 2,661
- 4
- 33
- 45
15
votes
1 answer
constexpr global of class type
My understanding is that constexpr globals of class type are all but unusable because
Such an object must be defined in every TU, because constexpr does not permit forward declaration of an object.
Default linkage as static would cause naming the…

Potatoswatter
- 134,909
- 25
- 265
- 421
15
votes
6 answers
Global variables in recursion. Python
OK, i'm using Python 2.7.3 and here is my code:
def lenRecur(s):
count = 0
def isChar(c):
c = c.lower()
ans=''
for s in c:
if s in 'abcdefghijklmnopqrstuvwxyz':
ans += s
return…

Carles Mitjans
- 4,786
- 3
- 19
- 38
14
votes
2 answers
global constants without using #define
Ok, I'm looking to define a set of memory addresses as constants in a .h file that's used by a bunch of .c files (we're in C, not C++). I want to be able to see the name of the variable instead of just seeing the hex address in the debugger... so I…

Kira Smootly
- 207
- 2
- 4
- 6
14
votes
2 answers
Is a "Globals" class holding static variables in Android safe?
Can anyone enlighten me about the safety of a class holding global values in Android?
Here's a short example of what I mean:
public class Globals {
public static int someVariable = 0;
public static User currentUser = null;
public static…

z00l
- 895
- 11
- 21
14
votes
2 answers
Is it possible to import to the global scope from inside a function (Python)?
I am trying to import a module from inside a function and have it be available to my whole file the same way it would be if I imported outside any functions and before all the other code. The reason it is in a function is because I don't have much…

scott77777
- 698
- 2
- 7
- 18
14
votes
6 answers
Python global variable
def say_boo_twice():
global boo
boo = 'Boo!'
print boo, boo
boo = 'boo boo'
say_boo_twice()
The output is
Boo! Boo!
Not as I expected. Since I declared boo as global, why is the output not:
boo boo boo boo

Don Lun
- 2,717
- 6
- 29
- 35
14
votes
2 answers
AutoMapper to apply common/global formatter on all fields?
I am using AutoMapper 3.2.1
I just got a requirement where the consumers of my project want me to do some simple transformations -- have all string fields trimmed of whitespace and convert null to string.empty.
How would I do this in AutoMapper in…

Raymond
- 3,382
- 5
- 43
- 67
14
votes
4 answers
Setting $_POST for filter_input_array(INPUT_POST) in phpunit test
Having some issues using PHPUnit to test my controllers.
Code I was working on so far was implementing $_POST or other request variables:
$_SERVER['REQUEST_METHOD'] = 'POST';
$_POST = array(
'test' => true
);
Most of tests worked perfectly this…

yergo
- 4,761
- 2
- 19
- 41
14
votes
5 answers
R scoping: disallow global variables in function
Is there any way to throw a warning (and fail..) if a global variable is used within a R function? I think that is much saver and prevents unintended behaviours...e.g.
sUm <- 10
sum <- function(x,y){
sum = x+y
return(sUm)
}
due to the "typo" in…

Jonas
- 1,639
- 1
- 18
- 29
14
votes
2 answers
What's an npm command to install devDependencies globally?
I'd prefer to type a short command, like npm install -g, to setup a project's global dependencies, such as node-sass and jshint, than manually typing out npm install -g every single package. Is there an npm-idiomatic way to do this?

apennebaker
- 681
- 2
- 8
- 17
14
votes
4 answers