variable-scope

Problem passing integer variable into click event in javascript and jquery

This is probably something simple but it's driving me nuts. I'm making some pagination using jquery and a while loop which has a variable called "pageNum" that updates at the end of the loop and represents the page being written out. Obviously pageNum is added to at the end of each iteration. Fine. Here's the code that's giving me a ha...

Need help with variable scope in Javascript

I have the following Javascript function that should return an array of groups that are in database. It uses $.getJSON() method to call get_groups.php which actually reads from the database. function get_groups() { var groups = []; $.getJSON('get_groups.php', function(response) { for (var i in response) { gr...

PHP Variables Scope

file name myServices.php <?php $gender = 'MALE'; ?> in another file lets say file.php include "myServices.php" $name = 'SAM'; $age = '23'; ?> <!--after some more HTML code--> <?php $gender = 'FEMALE'; $name = 'ELENA'; //Question: //In the above statements are there new variables crea...

Does Fortran preserve the value of internal variables through function and subroutine calls?

After much painful debugging, I believe I've found a unique property of Fortran that I'd like to verify here at stackoverflow. What I've been noticing is that, at the very least, the value of internal logical variables are preserved across function or subroutine calls. Here is some example code to illustrate my point: PROGRAM function...

Where should I store data/state information as I switch ViewControllers?

Hi, I am just starting to develop on the iPhone and was wondering about storing data that the user is entering into my application. Question: My application is organized as: UITabController LoginViewController (UIViewController) UINavigationController CustomViewController1 (UIViewController) CustomViewController2 (UIViewControlle...

Understanding variable scopes in php

echo "Point1, a=".$a."\n"; echo "Point1, b=".$b."\n"; if(1<2) { $a = 6; $b['link'] = "here"; echo "Point2, a=".$a."\n"; echo "Point2, b[link]=".$b['link']."\n"; } echo "Point3, a=".$a."\n"; echo "Point3, b[link]=".$b['link']."\n"; Why does the above code print out the following? Point1, a= Poin...

Variable Scope Question PHP

In the following code the variable does not seem to be getting set. Seems simple enough but for some reason this is vexing me. function teasertext($string){ $tstring = ""; if (strlen($string)>9){ $tstring .= substr($string,0,9) . "...."; } else { $tstring .= $string; } } print $tstring; return $ts...

I can pass a variable from a JSP scriptlet to JSTL but not from JSTL to a JSP scriptlet without an error

The following code causes an error: 1. <c:set var="test" value="test1"/> 2. <% 3. String resp = "abc"; 4. resp = resp + test; 5. pageContext.setAttribute("resp", resp); 6. %> 7. <c:out value="${resp}"/> The error says "error a line 4: unknown symbol 'test'". How do I pass test from the JSTL code to the JSP scriptlet? ...

try block scope

I'm unhappy with the rule about variable scope in a try block not being shared with associated catch and finally blocks. Specifically it leads to code like the following: var v: VType = null try { v = new VType() } catch { case e => // handle VType constructor failure (can reference v) } finally { // can reference v. } As oppos...

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 ...

Scoping in Python 'for' loops

I'm not asking about Python's scoping rules; I understand generally how scoping works in Python for loops. My question is why the design decisions were made in this way. For example (no pun intended): for foo in xrange(10): bar = 2 print(foo, bar) The above will print (9,2). This strikes me as weird: 'foo' is really just control...

python - strange behavior question

>>> class S(object): ... def __init__(self): ... self.x = 1 ... def x(self): ... return self.x ... >>> s = S() >>> s.x 1 >>> s.x() Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: 'int' object is not callable Why, in this example, is s.x a method, but also an integer? I...

PHP variable scope question

According to the PHP manual $a should be available to b.inc in the following code segment: <?php $a = 1; include 'b.inc'; ?> However when I try to do the same when calling a static method, $a seems to be out of scope. class foo { public static function bar() { $a = 1; include('b.inc'); } } foo...

Javascript function change variables scope

I am attempting to declare a function outside of anonymous function but still have acess to all of the anonymous functions variables Below is demonstrating what I'm talking about. I just need to get rid of eval. //Used to determine where the variable is being stored var variableScope = "global"; (function(window){ var variabl...

Static variables in C++

I would like to know what is the difference between static variables in a header file vs declared in a class. When static variable is declared in a header file is its scope limited to .h file or across all units. Also generally static variable is initialized in .cpp file when declared in a class right? So that does mean static variable s...

What is the scope of this object

I have the following code snippet which uses'event' My fellow developers argue that the scope of 'var event' is restricted to 'if' condition. Is that true. How can I make this a better code function prepForDrag(obj, event) { if(event= "undefined"){ var event=obj || window.event; } if (event.altKey) { ...

How scoping is handled in exceptions

How is the scoping of variables handled during exceptions? I suppose this will be language specific, and answers for any specific language are greatly appreciated. At least maybe the big ones? C++, python, Java. This is what I mean: python try: for k, v in map.iteritems(): cnf.conf.set( section, k, ...

Syntax or construct to simplify if() statement?

I'm looking for a semantic or language construct that will simplify some of my if statements. If I have an if statement with an or, where I 'choose' between two values, I'd like to have that chosen variable available later on in the code. I'll write this in pseudo-code: if ( x or y ) { function(z); } Where z is the value of x o...

Variable out of scope when entering a while loop in php

I have a problem when trying to populate an array in php. It seems that once I enter a while loop with a mysql_fetch_assoc method I cannot populate my array. I've included the code below. $params = $_REQUEST['params']; $arr["status"]="ok"; $projects=array(); $files=array(); $titles=array(); $query = 'SELECT p.id as pid, f.f...

From within a servlet how do you access a variable set inside a corresponding servlet filter?

I'd like to use the following filter to open and close persistence managers. public final class PersistenceFilter implements Filter { private static final PersistenceManagerFactory persistenceManagerFactory = JDOHelper.getPersistenceManagerFactory("transactions-optional"); private static PersistenceManagerFactory factor...