In the UK now (possibly the EU) at the end of your contract (normally 18-24 months) the carrier has to unlock your phone now, my brother just came to the end of his contract and had his iPhone unlocked for free.
In the EU in general you can unlock your phone for a price, even if you're under contract.
The last time I checked Orange was charging something like 70 EUR for unlocking iPhones under contract, which is really not bad, considering you get the freedom to put any SIM in it after that.
Also, my own mobile carrier (Cosmote) sells subsidized unlocked iPhones. Basically for them the contract is enough to keep you "locked" as if you terminate early, you have to give back the subsidy you received for the remaining time, which is fair to both consumers and the mobile carrier.
It's crazy how better the mobile carriers are in Europe, versus the US.