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