Questions tagged [global-scope]

Global scope defines a namespace that is fully accessible in the entire program or script.

Global scope defines a namespace that is fully accessible in the entire program or script. Variables, classes and objects that are defined in the global scope can usually be accessed anywhere in the code, and are often referred to as global variables.

108 questions
1
vote
1 answer

KeyError: global not accessible through imported class

I am trying to calculate the number of elements in a chemical equation. The debugger that I have created somehow doesn't have access to the globals within my program. Specifically, I am trying to access carrots but left is not being added to the…
cwahls
  • 743
  • 7
  • 22
1
vote
1 answer

PHP: use one global file pointer in a static `log` method

I'd like to call a log method statically throughout my app: App::log('Some message'); but then I'd like to create a file pointer only once, so that it's accessible from within that method($file_pointer) each time it's called. public static…
Alan
  • 1,322
  • 1
  • 21
  • 36
1
vote
2 answers

Define a macro to be run at global scope without warnings

The following code is OK, but I get a warning due to the extra ';' after INIT. #define INIT \ namespace Vars { \ int a = 0; \ } INIT; int main() { ... } How can I fix this code, allowing the notation with the extra ';'? Consider…
Pietro
  • 12,086
  • 26
  • 100
  • 193
1
vote
0 answers

Detect type of DML statement when using Global Scopes (Laravel/Eloquent)

I want to use an Eloquent Global Scope that will add a join to every select query for some models. The problem I'm facing is that the join is also added on other statements like UPDATE for example which makes the query invalid. The main idea for the…
Julian
  • 111
  • 3
  • 9
1
vote
1 answer

Declaration found during unqualified name lookup

Consider the following simple example: #include int a=5;//1 extern int a;//2 int main(){ cout << a; } The standard said that (sec. 3.4/1): Name lookup shall find an unambiguous declaration for the name and (sec. 3.4.1/1): name…
St.Antario
  • 26,175
  • 41
  • 130
  • 318
1
vote
1 answer

How to reset global variables between app

I have declared a class extending Application to keep some global array variables between activities of my app. When i stop the app and execute it again these values persist which i do not want. So I want to know how to reset these values when the…
Sanjay Bhatnagar
  • 111
  • 1
  • 1
  • 6
1
vote
1 answer

how come calling window.init from a global init function doesn't cause an infinite recursion?

So, how come this code doesn't loop infinitely? window.init = function(){ console.log("window.init") } function init(){ console.log("init") window.init(); } init(); jsfiddle: http://jsfiddle.net/FAt6C/
bigblind
  • 12,539
  • 14
  • 68
  • 123
1
vote
4 answers

What's the difference between a javascript function as a property of window, a function defined with a name

What's the difference between function doStuff(){ //do lots of fun stuff } and window.doStuff = function(){ //do lots of fun stuff } if any?
bigblind
  • 12,539
  • 14
  • 68
  • 123
1
vote
2 answers

CodeIgniter login across all pages

I'm am very new to CI the MVC model. I have a simple page which is made of up 3 views. Header, Content and Footer. The content will be unique across the site but header and footer will be the same, no matter what page. In my header I have a login…
Krimson
  • 7,386
  • 11
  • 60
  • 97
1
vote
1 answer

$GLOBALS between pages PHP 5.4 index error

It was my understanding that $GLOBALS was a super global and enabled a scope to extend across all pages. I'm a noob to PHP and I have been trying to pass a value from one page to another like so: A.php - reads $GLOBALS['A'] = 'Passed A'; echo…
1
vote
2 answers

How to append text to a variable, within a function, in Javascript?

var err = ''; err += 'err a'; myString = 'Blah'; new Ajax.Request('/check_me.php', { method:'get', parameters: { 'string': myString }, evalScripts: true, onComplete:…
TigerTiger
  • 10,590
  • 15
  • 57
  • 72
0
votes
1 answer

CakePHP function reachable from eveywhere

Where in cake to create a function that will be able to be used by any controller, model, view and every other place. I know that this is not very OOP but I need a function for checking the mime_type of files. ATM I em using a variable set in the…
user1018809
  • 211
  • 1
  • 3
  • 12
0
votes
3 answers

get data from coroutine globalScope in Room database kotlin

I want to fill the ProductList in the code below but it's always null. do you have any solution? fun nameValidation(name: TextInputEditText, cactusDao: CactusDao): String? { val nameText = name.text.toString() var…
0
votes
1 answer

Expose Functions Using Webpack & Then Call Them From an Inline Script

I'm working on getting a bunch of legacy inline scripts cleaned up. My question is: How do I call a function from an inline script that is compiled in WebPack. After trying a bunch of different things, I understand that I need to use…
Ryan Dorn
  • 679
  • 2
  • 8
  • 20
0
votes
1 answer

Laravel - Controller dependency is injected before middleware is executed

So I created a middleware to limit the data a connected user has access to by adding global scopes depending on some informations: public function handle(Request $request, Closure $next) { if (auth()->user()?->organization_id) { …