Most voted "global-variables" questions
In computer programming, a global variable is a variable that can be accessed in any scope (unless it is shaded). Mechanisms of interaction with global variables are called global environment mechanisms. The global environment paradigm contrasts with the local environment paradigm, where all variables do not use shared memory ( so all interactions need message passing).
Learn more…28 questions
Sort by count of
-
42
votes3
answers3888
viewsWhy is using global variables not good practice?
I’m reading a Javascript book called "Javascript The Good Parts" and in it at various times the author says that one should not use global variables because they are of "evil". Why are they…
-
33
votes3
answers1026
viewsWhat problems can a global state entail?
What problems can a program face with the use of global states? Where can it be acceptable? That is, how to know if I am abusing the resource? What alternatives exist to avoid this? I’ve already…
-
17
votes3
answers72012
viewsGlobal variable in Javascript
How to make a global variable in Javascript? I need the variable that was declared in one function to work in another function. Example: Jsfiddle $("#div3").click(function() { var fill = "a"; });…
-
11
votes3
answers1027
views$GLOBALS to store settings?
Hi, last week I asked what was the best way to store and read settings for a website, and I got two answers. Of those two answers, there was a lot of speculation, but none really explained why I…
-
11
votes1
answer363
viewsCustom global variable
In that question here, I explained that I was afraid to save my settings in the variable $GLOBALS because she turns my settings into global values, then the guy answered me that there was no…
-
6
votes1
answer111
viewsDifference between overall, const and define()
So I was studying about POO and MVC structures with PHP and saw that we often need to use global variables (accessible throughout the application) and what’s the difference of using: global $nome =…
-
5
votes1
answer198
viewsGlobal Differences in Userscripts in Chrome and Firefox
I started programming Userscripts in Chrome and almost all snippets of code I find work, but when going pro Firefox gives problem. In Chrome I use the Tampermonkey and in Firefox the Scriptish…
javascript google-chrome firefox global-variables userscriptsasked 10 years, 2 months ago brasofilo 6,560 -
4
votes3
answers3392
viewsHow to use static and global variables in PHP?
I need the value of a variable in several functions to increment and decrement the value of the variable. I have tried using static variable started with null value, but even changing its value, it…
-
4
votes2
answers18066
viewsAccess variable inside and outside a function
It is possible to access a variable inside a function outside of it? I would like to use a variable that was created in a function outside of it, but without returning by return of function. In PHP…
-
4
votes1
answer1504
viewserror: initializer element is not Constant
I’m trying to declare this buffer overall and when compiling it presents the following error error: initializer element is not Constant char *ls_buffer_PPouAUT = malloc(5120*sizeof(char)); How can I…
-
3
votes2
answers1007
viewsMulti-language system
I have a website and I would like to implement a multi-language system. I have some questions about good practice. I wish I had just one domain ****.com. I think this would require me to use systems…
-
2
votes2
answers438
viewsPHP global array as time table
I’m in the middle of a problem, I’d like to use a array as a table temporary, sort of like this: $array = [ "codigo" => "0123", "descricao" => "produto" ]; But I would need him to go global,…
-
2
votes1
answer130
viewsUse of superglobals within a session
index php. <?php include './db_unifacex.php'; session_start(); $_SESSION['contador']=0; ?> <html> <head> <meta charset="UTF-8"> <title></title> <meta…
-
1
votes1
answer6433
viewsPython local and global variables
I have a software that treats dates, written as follows: def EscolheDataInicio(): controle1 = None controle2 = None if controle1 == None: teste = easygui.ccbox(msg="Escolher data início?",…
python variables variable-declaration global-variablesasked 7 years, 1 month ago Bergo de Almeida 181 -
1
votes1
answer511
viewsI cannot increment a global variable in function parameter
What was asked of me: Declare a global variable called counter and assign it 0. Declare a Function called incrementCounterBy, which receives a Parameter called amount. It should increment counter by…
-
0
votes1
answer343
viewsDifficulty updating global variable. c
I am developing the following code and I am using global variables that can be changed in different parts of the code, but when I change for example the state variable in the menu() function its…
-
0
votes0
answers75
viewsHow to create global variable in php?
I am working with the codeigniter framework completely separate from the front-end. That is, I run the business rules and send a json to the controller. However, I am doing an authentication to…
-
0
votes1
answer189
viewsGlobal Variable with Typescript
So... I’m making a code in Typescript in which I need to use a variable from another script, I’ll make it clear below: <script type="text/javascript"> var global = "Variável…
-
0
votes1
answer67
viewsGlobal variable does not change the value
I’m a beginner and I don’t know why this code doesn’t work. Can someone tell me why? def teste(): global res1 res1 = input().strip() if res1 == '1': print('funciona')…
-
0
votes1
answer638
viewsHow to make a global variable in PHP?
I have a login, and if the credentials are correct it opens another PHP file and wanted the name of the person associated with the credentials used in the login to appear on a label. All the…
-
0
votes3
answers1664
viewsHow to use a Global variable in two Jquery codes to perform conditions?
It follows a simplified example of what I am doing. I need to check if the variables passed before and that would modify the Global are true in the checkbox. $(document).ready(function() { var…
-
0
votes1
answer510
viewsCounter of recursion solutions
Hi, I made a recursive Sudoku program, it’s working fine, but I’d like to add a solution counter, I’ve tried numerous code changes that would make it possible, but it didn’t work, finally I tried a…
-
0
votes1
answer84
viewsWhy is the text label not changed?
I have a screen class, which contains a label of text, the code loads an xml containing the objects. py screen.: #!/usr/bin/python3 import gi import modulo_arquivos import os…
-
0
votes0
answers287
viewsTurning all variables into global variables
I am developing a project and it works with many files and these files are called via require_once(). It is hard work to declare each variable created as a global variable in view of the number of…
-
0
votes1
answer275
viewsIs it recommended to use a global variable for a PDO object?
Below I will pass an example of how I use today the PDO connection to access my databases. I would like to see with you, if it is a good practice this way, or if it is recommended a safer and more…
-
0
votes1
answer208
viewsHow to use a global variable in a python function?
I’m trying to make a system of lootbox in python, but I can’t use an outside variable within the function from main import player from random import randint p1 = player class item: def lootbox(a,c):…
-
-2
votes3
answers143
views$_ has any meaning in question?
In "execution blocks" I see a lot $_SESSION for validation of forms and related, but did not understand very well what exactly means.
-
-2
votes1
answer117
viewsWhy do they say that the use of global variables is bad practice?
I’ll get straight to the point. In internet tutorials outside, you always find someone criticizing some, considering it as a "bad practice". For example, one of them is the use of the keyword…
programming-principles paradigms global-variablesasked 8 years, 6 months ago Wallace Maxters 102,340