scope

Can I pull all php global variables into the function's local scope?

♀尐吖头ヾ 提交于 2019-12-08 13:24:57
问题 In order to use variables outside of a function, I have to do this: <?php $a = 1; $b = 2; function Sum() { global $a, $b; $b = $a + $b; } Sum(); echo $b; ?> What if there are a lot of global variables, and I just want them all to be locally scoped inside the function? How do I do this without maintaining a long list of global declarations at the beginning of each function? I'm not concerned about best practices, or all the reasons it may be considered dangerous. 回答1: Ideally , everything your

How do I pass a string value from a TextBox between Forms?

断了今生、忘了曾经 提交于 2019-12-08 13:09:03
问题 I have two forms: Form1 which is my app and Form2 which is a login page. I want to pass a value entered into the username textbox (LoginTbox) on Form2 to Form1. This is what I have so far. No error is received, but it seems to be passing nothing. I've tried constructors, but couldn't seem to get that to work either. What am i doing wrong? Program.cs static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Form2 fLogin = new Form2(); if

Pulling indexes from an array and variable scope

只愿长相守 提交于 2019-12-08 12:20:31
问题 I'm running through TestFirstRuby and I've been stuck on problem 12, building a Reverse Polish Notation calculator. I've gotten through all of the tests except for the last one, asking me to take a string ("1 2 3 * +" and then "1 2 3 * + 4 5 / -"), and then evaluate the expression. What I'm trying to do is convert the string to an array, changing the numbers into integers and the operators into symbols, then go through the array and evaluate the expression anytime it comes to an operator.

access variables from other function c++

百般思念 提交于 2019-12-08 12:18:25
问题 I must access variables declared inside other function. Assume f1() void f1() { double a; int b; //some operations } and f2() void f2() { //some operations //access a and b from f1() } Is it possilbe in c++? How can that be done? Passing reference to function as shown here is not suitable answer for my case because this corrupts the order of calling functions. Declaring global variables also denied. 回答1: In C++ there is no way to access locally declared function variables outside of that

Why data Shadowing with instance variables is not working in my program?

99封情书 提交于 2019-12-08 12:15:31
问题 I have three classes which are shown below ,for a game GUI:- //this is the parent class. import javax.swing.*; import java.awt.*; public class GameGui extends JFrame{ public void decorateButton(JButton aBut,Color forg,Color back){ Font afont = new Font(Font.SANS_SERIF,Font.PLAIN,18); aBut.setFont(afont); aBut.setBackground(back); aBut.setForeground(forg); } public void setFrameDefault(){ this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setSize(400, 475); this.setLocationRelativeTo

JqGrid: Trying to add a + button to the right of a “add” form field (using elmsuffix)

☆樱花仙子☆ 提交于 2019-12-08 12:08:58
问题 I can get the icon to show up, and it fires a simple alert if I place the javascript line in the href but I cannot attach a dialog object to the link id. I am using "elmsuffix" to get the html there: This works: {name:'name',index:'name',width:100, editable: true, formoptions:{elmsuffix: "<a id="companysearch" href="javascript:alert('yay it worked!');" ><span id="companysearchicon" class="ui-icon ui-icon-plus" style="position:absolute; top:2px; right:25px; "></span></a>"}}, This does not: $("

Get access to CDI bean from another CDI bean

和自甴很熟 提交于 2019-12-08 11:44:46
问题 I have to get access to a session scoped CDI bean from another request scoped CDI bean. I have got: the session scoped CDI bean which keeps a logged in user, the request scoped CDI bean which processes some data and needs (for this purpose) of the instance of currently logged in user. At the moment when I try to get access to the session scoped bean from request scoped bean (through the @Inject annotation) as you see below - I get the NullPointerException exception in this line (which is

Scope for getJSON in jQuery

纵然是瞬间 提交于 2019-12-08 11:15:35
问题 I'm having a bit of trouble trying to manage scope when using getJSON. So on a HTML page I have an unordered list to be filled with list items from a JSON file. The list is markup for a carousel. HTML: <ul class="carousel"></ul> JS: grabJSON : function() { $.getJSON('file.json', function(data) { var items = []; $.each(data.foo, function(k, v) { items.push('<li>' + v.bar + '</li>'); } $('ul.carousel').append(items.join('')); // carousel action here $('ul.carousel').carouselFunction({ //

JavaScript variables hoisting in nodejs/async

允我心安 提交于 2019-12-08 10:44:16
问题 In the next example I don't have access to variable "locals" inside the functions "fetcher", "parser" and "saveToDb". var parser = require('parser.js'); var fetcher = require('fetcher.js'); var saveToDb = require('models/model.js'); var async = require('async'); function task() { var locals = [] //<-- declared here async.series([ fetcher, //<-- can not access "locals" parser, //<-- can not access "locals" saveToDb //<-- can not access "locals" ], function (err) { if (err) return callback(err)

How to understand Javascript in deep with var scope & closure? [duplicate]

微笑、不失礼 提交于 2019-12-08 10:36:20
问题 This question already has answers here : Javascript function scoping and hoisting (16 answers) Closed 2 years ago . I just can't understand why the the a1 = function ? and where is my value 1 that was passed to the fn() , whether it was overrwrited by var a ? the problem look like caused by the same names( var & function) ! function fn(a) { console.log("a1 = " + a); var a = 2; function a() { } console.log("a2 = " + a); } fn(1); // a1 = function a() { } // a2 = 2 function fnx(ax) { console.log