Questions tagged [global-variables]

Global variables are variables that are accessible from all elements of a software component.

Global variables are variables that are accessible from all elements of a software component.

Global variables are used to share information between elements of a component and to store a part of the component's state. They therfore:

  • create a hidden coupling between all the elements that use them;
  • are a source of accidental bugs and inconsistencies, when changes and side-effects are not sufficiently controlled.
8810 questions
2
votes
2 answers

Why does a variable in my program use 60% of the execution time?

i'm analysing my code with gprof, and i get the following output: % cumulative self self total time seconds seconds calls ms/call ms/call name 59.22 0.58 0.58 48 12.09 18.81 …
Jon V
  • 506
  • 1
  • 3
  • 21
2
votes
4 answers

Errors with a shell-script

i found some freaky error. I want to increment a counter, but the variable isnt visible outside the while do. The script as follows: ## $1 - The file which should be examined ## $2 - The time passed between the checks. If $2 is 5 then all lines…
2
votes
4 answers

Access variable defined in other file from class

I would like to know if there is a way to access a variable defined in an other file from a class in PHP. Example : file_01.php file_02.php
Doc_1faux
  • 141
  • 5
  • 15
2
votes
3 answers

Global Variables and Modules (simple example help) Python

OK I am doing some threading, and I guess when I started doing threading I assumed you can't return values like a definition (its the end of the day and my brain is about to die so maybe this is incorrect and I should start going back to get rid of…
Sean Cav
  • 133
  • 1
  • 14
2
votes
4 answers

What $_SERVER variable provide full URL

Possible Duplicate: getting current URL PHP and invoking url? Say somebody is looking for http://subdomain.domainname.com/somedirectory/somefile.htm What $_SERVER variable contain http://subdomain.domainname.com/somedirectory/somefile.htm
user4951
  • 32,206
  • 53
  • 172
  • 282
2
votes
1 answer

What's the easiest way to define an app global variable which can be used by all the classes?

I'm making an app where I would need to set two global variables, which should be able to be modified by any class in the entire app. I tried setting on the appDelegate, on a GlobalClass class, on main.m, as a @property declaration, but I don't…
pmerino
  • 5,900
  • 11
  • 57
  • 76
2
votes
3 answers

bash save last user input value permanently in the script itself

Is it possible to save last entered value of a variable by the user in the bash script itself so that I reuse value the next time while executing again?. Eg: #!/bin/bash if [ -d "/opt/test" ]; then echo "Enter path:" read path p=$path else…
user465465
  • 441
  • 3
  • 13
  • 26
2
votes
1 answer

Best way to setup a variable for Global use in CodeIgniter?

I'm using CodeIgniter and I have user data that needs to be stored in some way then updated. Basic things like name, id, points, comment count etc At the moment when the user logs in I simply get their data and store it in a session. Now obviously…
Sean H Jenkins
  • 1,770
  • 3
  • 21
  • 29
2
votes
2 answers

pros and cons for implemeting a global object in Android/Java as singleton or DataClass

There are many questions and answers on how to implement a global variable in Android/Java. So it seems one can either implement a singleton or use a data class itself with static variables. I am about to start a larger project and would like to…
user387184
  • 10,953
  • 12
  • 77
  • 147
2
votes
2 answers

Initialize variable by passing a reference on a function

I'm wondering how could you initialize a variable by passing it as a reference on a function. Here is the code: var carToy, trainToy; function setToyValue(name, description, toy) { toy = new makeToy(name, description); } function makeToy(name,…
Óscar
  • 341
  • 1
  • 2
  • 14
2
votes
2 answers

Why I have to nullify all of the session variables?

Why I have to nullify the session variables?Is session_destroy not enough?
giannis christofakis
  • 8,201
  • 4
  • 54
  • 65
2
votes
3 answers

Best practice location for option values for classes

With a PHP MVC project, I have a few model classes that load data from a RESTful web service, which requires an API key. I'd like to store the necessary API key in the central config file of my application. To get that API key to my class, which…
Brad
  • 159,648
  • 54
  • 349
  • 530
2
votes
1 answer

storage class specified for 'FileCase' error

I tried to compile some code however am getting the error storage class specified for 'FileCase' What does this error mean? Does it have to do with the fact I have declared it as an extern int in the private part of the header file ? I am…
jis
  • 75
  • 1
  • 2
  • 10
2
votes
5 answers

Assigning ajax call return value to an var with jquery

How can I assign a variable(var) to a json object which is returned from ajax call to the server? I need to access that object in the rest of the body. For example, I've try this, I don't know it's correct. var…
Abimaran Kugathasan
  • 31,165
  • 11
  • 75
  • 105
2
votes
1 answer

Tomcat global variable

I was wondering if there is a global session concept in tomcat (à la PHP). Imagine a really vanilla webapp with a servlet that takes input via POST and dumps them into an object (ignore obvious security concerns). The index page then just displays…
Victor Parmar
  • 5,719
  • 6
  • 33
  • 36