scope

Can callback methods in PHP's session_set_save_handler be private?

I am writing a custom session handler in PHP and trying to make the methods defined in session_set_save_handler private. session_set_save_handler( array('Session','open'), array('Session','close'), array('Session','read'), array('Session','write'), array('Session','destroy'), array('Session','gc') ); For exampl...

Do you use curly braces for additional scoping?

I mean other than using it when required for functions, classes, if, while, switch, try-catch. I didn't know that it could be done like this until I saw this SO question. In the above link, Eli mentioned that "They use it to fold up their code in logical sections that don't fall into a function, class, loop, etc. that would usually be ...

In C++, is it safe to extend scope via a reference?

In C++, is it safe to extend scope via a reference? In code, what I mean is: MyCLass& function badIdea() { MyClass obj1; ... return obj1; } ...

Using C++ from Objective C : how to allocate/deallocate?

Currently, my Objective C classes use C++ objects by doing a new when the owner is created, and calling delete when it is destroyed. But is there another way? I'd like to be able to declare, say, an auto_ptr whose scope lasts the duration of the Objective C class' lifetime. ...

How does VC++ mangle local static variable names?

Here's some code I have: MyClass* MyClass::getInstance() { static MyClass instance; return &instance; } I want to look into this singleton's current values. But I'm currently paused three hours into execution, and the reason I'm paused is that I'm out of memory. So I can't put a breakpoint in this method there to see what the va...

when does a thread go out of scope?

I've written a program that counts lines, words, and characters in a text: it does this with threads. It works great sometimes, but not so great other times. What ends up happening is the variables pointing to the number of words and characters counted sometimes come up short and sometimes don't. It seems to me that the threads are some...

In SQL, can I use a variable scoped outside a nested select within the nested select itself?

I'm trying to get the following SQL statement to work: UPDATE myschema.tableA update_tableA SET field_id = ( SELECT src.field_id FROM myschema.srcTable src INNER JOIN myschema.tableB tableB ON update_tableA.id = tableB.id AND SDO_ANYINTERACT( tableB.shape, src.shape ) = 'TRUE' ); Whe...

Short Description of Python Scoping Rules

What exactly are the Python scoping rules? If I have come code: code1 class Foo: code2 def spam..... code3 for code4..: code5 x() Where is x found? Some possible choices include the list above: In the enclosing source file In the class namespace In the function definition In the for loop index varia...

c# Pre-processor directive scope

Im looking to use: #define and #if to allow me to simulate potentially absent hardware during unit tests. What are the rules for useing the #define statements? i.e. what is its default scope? can I change the scope of the directive? ...

Howto add dynamic search parameters to Sharepoint search?

So our scenario is this: We have multiple Sharepoint sites that are created dynamically on a "as requested" basis. Basically there's a new site for each new project. Now, for every site we want to add a search clause that says that only contents with a metadata tag value equal to the sitename should be found. Quick example: There are 2 s...

Weird scope issue in .bat file

I'm writing a simple .bat file and I've run into some weird behavior. There are a couple places where I have to do a simple if/else, but the code inside the blocks don't seem to be working correctly. Here's a simple case that demonstrates the error: @echo off set MODE=FOOBAR if "%~1"=="" ( set MODE=all echo mode: %MODE% ) else (...

How, where to store objects within different scopes in Asp.net 2.0

Hi guys, need ask you about some help. I have web app running in Net 2.0. I wanna ask what storage (cache, session, file) I should use for my objects as they have different scope of using. Can be divide into several groups: 1) objects related directly to visitor (e.g. details about visitor that are received after authentication) 2) o...

Why do new instances of a class share members with other instances?

class Ball: a = [] def __init__(self): pass def add(self,thing): self.a.append(thing) def size(self): print len(self.a) for i in range(3): foo = Ball() foo.add(1) foo.add(2) foo.size() I would expect a return of : 2 2 2 But I get : 2 4 6 Why is this? I've found that by doing a=[] in the init, I can ...

Dynamic Scoping - Why?

I've learned that static scoping is the only sane way to do things, and that dynamic scoping is the tool of the devil, and results only from poor implementations of interpreters/compilers. Then I saw this snippet from a Common Lisp vs. Scheme article: Both Lexically and Dynamically Lexical scope only, per the standard. scoped spec...

Object Scope - Objective C Question

This is a program I'm writing (myself as opposed to copying someone else's and thus not learning) as part of the ObjectiveC and Cocoa learning curve. I want to draw simple shapes on a NSView (limiting it to ovals and rectangles for now). The idea is that I record each NSBezierPath to an NSMutableArray so I can also investiagte/implement ...

Scoping issue in Python

Hi All, Can anyone help me to get info about the Scoping issue( Static and dynamic scoping) in Python ? Thanks ...

What type of scope does Haskell use?

I'm trying to figure out if Haskell uses dynamic or static scoping. I realize that, for example, if you define: let x = 10 then define the function let square x = x*x You have 2 different "x's", and does that mean it is dynamically scoped? If not, what scoping does it use, and why? Also, can Haskell variables have aliases (a diff...

Declaring variables within FOR loops

A weird bug was occurring in production which I was asked to look into. The issue was tracked down to a couple of variables being declared within a For loop and not being initialized on each iteration. An assumption had been made that due to the scope of their declaration they would be "reset" on each iteration. Could someone explain why...

A small question about python's variable scope

I am a beginner of python and have a question, very confusing for me. If I define a function first but within the function I have to use a variable which is defined in another function below, can I do it like this? Or how can I import the return things of another function into a function? for example: def hello(x,y): good=hi(iy,ix) ...

Python variable scope question

Hi, I've been programming for many years, and recently started learning Python. The following code works as expected in both python 2.5 and 3.0 (on OS X if that matters): a, b, c = (1, 2, 3) print(a, b, c) def test(): print(a) print(b) print(c) # (A) #c+=1 # (B) test() However, when I uncomment line (B), I ...