global-variables

Is using superglobals directly good or bad in PHP?

So, I don't come from a huge PHP background—and I was wondering if in well formed code, one should use the 'superglobals' directly, e.g. in the middle of some function say $_SESSION['x'] = 'y'; or if, like I'd normally do with variables, it's better to send them as arguments that can be used from there, e.g: class Doer { private $se...

Global instance in prototypal javascript

I am exploring a pattern where you can save a global reference to the current instance for simple use in anonymous functions where the this keyword is out of context. Consider this: var instance; var a = function(id) { instance = this; this.id = id; }; a.prototype.get = function() { return (function() { return instance.id; ...

Can I create custom global methods in my Android application class?

Hi all. I currently have an app that has many activities and needs to have a way of maintaining state between these activities. I use the Application class to do this, declaring my global variables and using getters and setters to interact with my activities. I was hoping to place a few custom methods in there, so that when I want t...

Global variables not destructed in main thread?

I have a mixed-mode executable and I noticed that the constructor of my native global variables is called in the main thread, but the destructor is called in some other thread. The name of thread is 'Thread::intermediateThreadProc'. The global variables are What is the reason for this? And what is this 'Thread::intermediateThreadProc'...

Objective-C changing random values for variables

This really is my last resort as I am absolutely stumped and I just know it is something stupid! I have a UITableView and a UISearchBar, the user uses the search bar to enter a location, which is then appended to a url with page=1. This is then sent to an api and a list of adverts are returned (this has been successful). The user can th...

Which is better: Dependency Injection+Registry or Dependency Injection or Global Registry?

Firstly, I want to restrict this question to web development only. So this is language agnostic as long as the language is being used for web development. Personally, I am coming at this from a background in PHP. Often we need to use an object from multiple scopes. For example, we might need to use a database class in the normal scope b...

Global array in C header?

Okay, strange question time! I'm refactoring some old C++ code that declares a bunch of arrays like so: static SomeStruct SomeStructArray[] = { {1, 2, 3}, {4, 5, 6}, {NULL, 0, 0} } And so forth. These are scattered about in the source files, and are used right where they're declared. However, I would like to move them in...

How to create a type-tag for template specialization

I have a custom logging class that supports iostream-syntax via a templated operator <<: template< class T > MyLoggingClass & operator <<(MyLoggingClass &, const T &) { // do stuff } I also have a specialized version of this operator that is supposed to be called when a log-message is complete: template< > MyLoggingClass & operat...

global variables in C++

In a C++ multi-threaded application with many classes, i am trying to find out what are the methods to define a global variable C style, define it as global in any one source file, define it as extern in a header which is included in the classes that access this variable. Write a Singleton class, which contains these global variables a...

Global Object not accessible to other source files C++

I have an ErrorLog class, that is used to write and modify log files. I'd like to write to it before and after major events for debugging purposes and I only want to use one instance of the ErrorLog class for the entire application. I tried declaring an ErrorLog object as a global by placing ErrorLog exe_log; into a header file so it is ...

How to pass data to plugins in Python?

I'm implementing a simple plugin framework for a little Python program and wonder whether there are general best practices for transferring data to plugins? I'm new to Python and this is what I have come up with so far after doing some reading: I will not use global variables, instead data is going to be passed to the plugin classes on ...

JavaScript .push() inside function is overriding global variable

Hi! I have the following problem with .push() method: var myArray = ["a", "b", "c", "d"]; function add(arr) { arr.push("e"); return arr; } add(myArray); // myArray is now ["a", "b", "c", "d", "e"] Why it overrides myArray? Can't understand that... ...

Where to put Global variables in Rails 3

I used to put Global variables in environment.rb with my Rails 2.3.8 application such as: MAX_ALLOWD_ITEMS = 6 It doesn't seem to work in Rails 3. I tried putting it in application.rb and that didn't help. What do you suggest? ...

iPhone Global Variable?

Hi I have two views with their own .h and .m files of course. How can I declare a bool (or any variable for that matter) in one view and be bale to access it in another view? Thanks. ...

How can I make a regular variable accessible in files included by a class method?

I have a php site which flows as shown below. Please note I'm leaving out most of the code (wherever theres an ellipses). index.php include template.php ... $_template = new template; $_template->load(); ... template.php class pal_template { ... public function load() { ... include example.php; ... } example.php ... global ...

Global multidimensional array not being written to [vs c++]

I have a global multidimensional array, g_iAllData[MAX_LEN][MAX_WIDTH] being used in a Form. When I write to it in a function: g_iAllData[iRow][iColumn]= iByte_Count; I can see in a Watch Window that it's contents are not being changed. If I put the array in the function, it works fine. Is there something I'm missing? I am declaring ...

Passing Several NSStrings to another view - Iphone

Hi In my iPhone app, the user will be making multiple NSStrings. Once these are made, I need to pass them to another view completely in the app. How can i do this? All I know at the moment os I can't access objects or variables declared in one view, in another. Thanks. ...

Is $view in an MVC php program a proper use of global variables?

I understand that global variables should be avoided generally. As a beginner, I'm trying to understand whether making a $view variable global in a dynamic web program built following MVC principles is one of those cases where globals are a good idea. In my program, I create the $view (as an object that contains an empty array) in inde...

Change Permanently Session System Variable in MySQL

I added this line to my.ini wait_timeout=2000000 When I type show global variables It prints wait_timeout=2000000, but when I type show variables It prints wait_timeout=28800 I can set with set wait_timeout=2000000 But I do not want to set it all the time manually. Do you have any suggestion to set permanently session sys...

Google Maps v3: Cannot access global variables

Not sure what framework (if any) Google Maps v3 is built on top of but I'm having issues trying to access global variables within the following function. var geocoder = new google.maps.Geocoder(); geocoder.geocode({ 'address': google_addresses_array[i][1] }, function(results, status) { if (status == google.maps.GeocoderStatus.OK) ...