assignment

PHP Conditional Operator and Self Assignment

Is this sort of thing considered OK in PHP? $foo = $_GET['foo']; $foo = empty($foo) || !custom_is_valid($foo) ? 'default' : $foo; Are there cleaner alternatives to this? I'm basically trying to avoid extra table look-ups. ...

How can I overload the assignment of a class member?

I am writing a Player model class in Python with Django, and I've ran into a small problem with the password member. I'd like the password to be automatically hashed upon assignment, but I can't find anything about overloading the assignment operator or anything. Is there any way I can overload the assignment of password so as to automa...

Is there any way to set an instance of an object to the current instantiated object within its own class?

I'm not sure really how to ask that question.. hopefully my explanation will clarify: I have a public method in a class, say Widget that takes a list of Widgets and makes changes to them. However, sometimes, the Widget calling the method is in that list. Is there any way to set the current object as one of the items in the list? For ex...

Flex 3: Data assignment to a subcomponent fails in an MXML component in the action script block

Hi there. I'm trying to propagate an assignment to the data parameter of a sub-component through it's parent component's setter. Like this: <CustomComponent xmlns:mx="http://www.adobe.com/2006/mxml" xmlns="components.*" > <mx:Script> <![CDATA[ public override function set data(val:Object):void { ...

Is there a defined evaluation order for &= and |= ?

If you have a C function which returns an integer, you could write a statement like this: MyInt &= MyFunc(); ...where we're using the bitwise-AND assignment operator. The question is: is MyFunc() guaranteed to be executed, even if MyInt equals zero? Likwise, if we used the bitwise-OR assignment operator (|=), would MyFunc() always b...

Smiley face when assigning improper value type to struct property!!

I am somewhat wondering if I am losing my mind, but I swear to you, this code outputs smiley faces as the .name values!! what in the world is going on? Thus far it seems to only work when the value is 1, anything else properly gives errors. I realize the code is flawed -> I do not need help with this. #include <iostream> #include <fstr...

VS2008 C++ Compiler error?

this compiles :-) string name; name = 1; this does not: string name = 1; any thoughts? I know that this is wrong. . . that is not the point. The first gives a smiley face. ...

Entity Framework: Assign entity to property of another entity

Hi, I have these entities (this is just an abstraction I created for this post): Language District Description These are the references between them: District * - 1 Language Description * - 1 Language District 1 - 1 Description If I fetch like this: var myFetch = from c in context.Districts where c.Id = 10 ...

Assigning a value when an exception occurs (Java)

Hello, Here is some sample code to illustrate our issue: A a = null; try { a = new A(); a = doSomethingThatWillThrowAnException(); } finally { System.out.println("A = " + a); } The question is what is the value of 'a' as printed in the finally block... I am not sure and I think I stumbled across something that might not be com...

How can you assign an event object to an event id in this example?

I don't know if this a Ruby question or a Rails question but in this example of a use of nested resources in Rails, how is it possible to assign an event object to an event_id? The event object would seem to represent a larger set of values than the event_id does. <%= link_to 'Tickets', event_tickets_path(:event_id => @event) %> ...

Simple C array declaration / assignment question

In higher level languages I would be able something similar to this example in C and it would be fine. However, when I compile this C example it complains bitterly. How can I assign new arrays to the array I declared? int values[3]; if(1) values = {1,2,3}; printf("%i", values[0]); Thanks. ...

String Assignment -Clarification

When i declare string x = new string(new char[0]); It works fine.My question is what value will be assigned to x ? when i check Console.WriteLine(x.CompareTo(null)==0);,it returns false. ...

in Java, I can't assign values to variables while i'm in the run() function of a thread-extended class.

This is my code. As you see in the run method, I assign values to tStart, tEnd, tAround and wTime. But when the Thread ends, they still have the default values of -1. I try printing out their values while the run() is running, and I have the correct values. But they are not 'writing' those values back to the variables when the thread end...

Fastest way to insert a word at the correct position in a dictionary

Currently, I'm simply inserting the word into the dictionary (ArrayList<String>) and then sorting the dictionary like so: dictionary.add(newWord); Collections.sort(dictionary, new Comparator<String>(){ public int compare(String s1, String s2) { return s1.compareToIgnoreCase(s2); } }); I'm trying to determine wh...

What is this syntax?

i = 1, 2, 3, 4, 5; this actually assigns 1 to i. I wonder if this type of assignment is actually useful somewhere? Do you know some application of this syntax? ...

Why does an assignment for double-sliced numpy arrays not work?

Hello everybody, why do the following lines not work as I expect? import numpy as np a = np.array([0,1,2,1,1]) a[a==1][1:] = 3 print a >>> [0 1 2 1 1] # I would expect [0 1 2 3 3] Is this a 'bug' or is there another recommended way to this? On the other hand, the following works: a[a==1] = 3 print a >>> [0 3 2 3 3] Cheers, Philip...

iPhone table view - some button/action questions

I created a table view that is populated with a custom UITableViewCell (like this). Each of the cells contains two UIButtons. I assign the action to the button like this: [decreaseButton addTarget:self action:@selector(decrease) forControlEvents:UIControlEventTouchUpInside]; Is this the right way? Anyway, it works, but in my "decreas...

PHP combining directions in switch to get diagonal text

[Disclaimer: I am new to PHP, and I am just learning, so please no flamers, it really hinders the learning process when one is trying to find solutions or information, thank you, and the code works fine in terms of the crossword puzzle, it's just really baffling me how one gets a diagonal orientation with the given information, or what I...

Copy constructor and = operator overload in C++: is a common function possible?

Since a copy constructor MyClass(const MyClass&); and an = operator overload MyClass& operator = (const MyClass&); have pretty much the same code, the same parameter, and only differ on the return, is it possible to have a common function for them both to use? ...

F# - Let and Property Assignment in one line

How can you write the following F# code (or similar) in one line: let contextMenu = new ContextMenuStrip() mainForm.ContextMenuStrip <- contextMenu I have to declare contextMenu as it will be needed later. Thank you ...