Working in Denmark. I took it up with my Union, and they said that I couldn't do anything about it.
The rule initially was made to own rights to images and articles from photographers and journalists, so they couldn't sell to third parties, but was extended to also include code.
We do have a similar rule (with similar origins), but it has to be contractually asserted, and it would only apply to portions of code integrated into a larger 'visual work' - mostly it doesn't come into play outside of contracting.
That is OFTEN how US employment contracts work though... Perhaps not in CA, but the rest of the US...
Every employment contract I've been asked to sign has had some level of owning stuff I do off-hours (up to everything you do any time on your own computers, everything you've done in the past, etc...).
I've always pushed back and gotten it changed to meet my needs.
It's how they're written, but not how they work. In reality, that type of claim is not enforceable.
It is a good signal that they will attempt to prove infringement on your outside work though, and you can't ever guarantee a win in that kind of court case; the case-law is too messy and depends heavily on unproveables like 'intent' and 'reasonability'.
Yes, yes it can. It all depends on the contract you sign. At present, it seems as if most tech shops allow you to moonlight on your own boxes. But I've looked over company policies which were "we own your brainz". HP circa 2006 was one of those, iirc.
No, it literally can't. It can be somewhat similar with contracts that promise a transfer of IP, but you'd get sued for breach of contract, not for copyright infringement.
That doesn't stop companies from putting draconian claims in their contracts and manuals, and it doesn't stop them from trying to prove infringement anyway (no copyright case ever is a 'sure thing'), which is enough to scare most employees into toeing the line. But they can't actually make unrelated work you do on your own time automatically 'work for hire'.
The pivotal words are "within the scope of his or her employment" - these words can get a little fuzzy, but http://www.wisegeek.com/what-is-scope-of-employment.htm is a reasonable (though not authoritative) discussion of the topic.
Where were you working? That's definitely not how US ip-law operates.