I answered a question on SO with code that came mostly from php.net. It was not immediately clear to me exactly what license, if any, applies to the example code on php.net. I can't claim ownership of it. How is this licensed?
As described by Machavity, the php.net manual has its license. As of this writing, that appears to be a CC with attribution 3.0 license. CC to CC license typically isn't all that much of a problem.
A more interesting situation would be one where someone is asking about a bit of code. Lets say... AbstractList form the openjdk. This code is covered under the GPL license.
Say a person is asking about the internal
Itr class to it and how the
It really boils down to two options.
One option is that the question provides a link to the code and doesn't include it. This would be very much like linking to a JSFiddle as the entirety of the question on SO - frowned upon. The relevant MSO post is Should a question that is meaningless without viewing an external link be closed? where ChrisF says:
You could also leave a comment explaining that questions (like answers) should really stand on their own merits and only have external links for references etc.
If the code is too long to post in the question then that's another sign of a bad question. The OP should really be able to narrow the problem down to a few lines of code. If they're not at that stage yet then Stack Overflow isn't the place they should be posting.
Though its not that the code is too long.
The other option would be to include the bit of relevant code. I'm looking at a dozen lines right here. Currently, I would argue that the incorporation of the code in the question would be covered by fair use. And... we've now entered the murky world of IANAL.
The question and the answers are talking about the code. It isn't granting the use of the code under any particular license - it isn't even intended to be used as code.
However, once someone says "all the code on the site is under MIT" now that code is code... and you probably can't include it because you can't relicense the GPL code as MIT code.
Stepping through some code for gcc, or openJdk in an post shouldn't try to make that code licensed under MIT. The unfortunate effect of trying to provide a license for the code in a question would be that any code that is in the question must be MIT (and SE waiver) compatible - or a link only. And that will be detrimental to the quality of questions and answers across the entirety of the SE network where code that may not be able to be relicensed in a way to be included is a necessary part of a post.
In your case it most likely doesn't apply. You used and linked code from the PHP manual which is under its own license which states
- License Grant. Subject to the terms and conditions of this License, Licensor hereby grants You a worldwide, royalty-free, non-exclusive, perpetual (for the duration of the applicable copyright) license to exercise the rights in the Work as stated below:
to Distribute and Publicly Perform Adaptations.
In other words, you took what was in the manual and adapted it for your answer. Since it wasn't a direct copy, you could (in theory) claim it as your own original work (as long as you attribute the original). Disclaimer I am not a lawyer so take that with a grain of salt.
The MIT debate is over someone taking the code you provided and using it, and then your claiming some form of copyright over it. All Stack overflow is trying to do is clarify the rights you, as a receiver of that code, have under the law.
I asked a similar question earlier on meta.SO.
For both the current CC-BY-SA and the proposed MIT license, my understanding is (IANAL) that you may take code licensed under an incompatible license (such as GPL) and post it to an SE site if you are commenting on or teaching others about how the code works. This would usually fall under fair use (but would vary from country to country).
Somebody else though would not be allowed to then take that code in the question or answer and use it solely under the current CC-BY-SA or the proposed MIT license. Presenting the code on SE may be fair use but the use of that code in another program is not. Thus it would be violating the original license which the copyright holder applied to the code.
If you are not the copyright holder then you cannot apply a new license unless the license specifically allows you to do so.