You just pay however much Apple sells the new one for.
I was under the impression that O2 recently changed their TOS.
Remember, in the UK, you must sign up for a service contract at the same instant as you purchase the iPhone - it's not like in the States, where you can just buy the phone at an Apple store and then sit on it with no obligation to immediately activate it and start paying for service.
So when you buy the next-generation iPhone, you'll be entering into a new contract, and you'll most likely want to terminate the old contract.
Originally, I understand that they had a clause in the contract stating that the iPhone contract's ETF would be waived if you were simply replacing a previous iPhone with a new iPhone under a new contract.
However, apparently the wording has changed. Now, if you end your original contract before the end of the 18 month period, even if you're replacing it with a new contract for a new iPhone, as I understand it, you'll have to pay an ETF to deactivate the old phone.
[edit] But time for some good news: it looks as though they're not holding people to the most draconian possible interpretation of the revised TOS. See here:
https://forums.macrumors.com/posts/4900094/